Programming/C

[백준] 단계별로 풀어보기 > 1차원 배열 (C언어)

코딩뽀시래기 2021. 3. 25. 02:35
728x90

+) 풀이 코드

https://github.com/jung0115/CodingTestPractice.git

 

GitHub - jung0115/CodingTestPractice: Practice Coding Test with Beakjoon, programmers, etc.

Practice Coding Test with Beakjoon, programmers, etc. - GitHub - jung0115/CodingTestPractice: Practice Coding Test with Beakjoon, programmers, etc.

github.com

 

10818번 - 2021.03.25.목

#include <stdio.h>
int main(void){
  int N, num[1000000], i, max, min;

  scanf("%d", &N);

  for(i=0; i<N; i++)
    scanf("%d", &num[i]);

  max = num[0];
  min = num[0];

  for(i=1; i<N; i++){
    if( max < num[i] )
      max = num[i];
    if( min > num[i] )
      min = num[i];
  }
  
  printf("%d %d", min, max);
  
  return 0;
}

 

2562번 - 2021.03.25.목

#include <stdio.h>
int main(void){
  int num[1000000], i, max=0;

  for(i=0; i<9; i++)
    scanf("%d", &num[i]);

  for(i=1; i<9; i++){
    if( num[max] < num[i] )
      max = i;
  }
  
  printf("%d\n%d", num[max], max+1);

  return 0;
}

 

2577번 - 2021.03.25.목

#include <stdio.h>
int main(void){
  int A, B, C, mul, num[10] = {0}, n, i;

  scanf("%d %d %d", &A, &B, &C);

  mul = A * B * C;

  while(1){
    n = mul%10;
    num[n]++;
    mul/=10;
    if(mul == 0)
      break;
  }

  for(i=0; i<10; i++){
    printf("%d\n", num[i]);
  }
  return 0;
}

 

3052번 - 2021.03.25.목

#include <stdio.h>
int main(void){
  int num[10], check[42]={0}, i, cnt=0;

  for(i=0; i<10; i++)
    scanf("%d", &num[i]);
  
  for(i=0; i<10; i++){
    check[num[i]%42]++;
  }

  for(i=0; i<42; i++){
    if(check[i] > 0)
      cnt++;
  }

  printf("%d", cnt);

  return 0;
}

 

1546번 - 2021.08.17.화

#include <stdio.h>

int main(void)
{
  int N, score[1000], max=0, i;
  double changeSum=0.0;

  scanf("%d", &N);

  for(i=0; i<N; i++){ //최대값 탐색
    scanf("%d", &score[i]);
    if(score[i] > max)
      max=score[i];
  }

  for(i=0; i<N; i++){
    changeSum += ((score[i]*1.0)/(max*1.0))*100.0;
  }

  printf("%lf", changeSum/(N*1.0));

  return 0;
}

 

8958번 - 2021.08.17.화

#include <stdio.h>

int main(void)
{
  int N, allScore, countScore, i, j;
  char answer[81];

  scanf("%d", &N); //테스트 케이스 개수

  for(i=0; i<N; i++){
    scanf("%s", answer);
    allScore=0;
    countScore=0;
    for(j=0; answer[j]!='\0'; j++){
      if(answer[j]=='O'){
        countScore++;
        allScore += countScore;
      }
      else{
        countScore=0;
      }
    }
    printf("%d\n", allScore);
  }

  return 0;
}

 

4344번 - 20210.08.17.화

#include <stdio.h>

int main(void)
{
  int C, N, score[1000], i, j, sum, cnt;
  double average, percent;

  scanf("%d", &C);

  for(i=0; i<C; i++){
    scanf("%d", &N);
    sum=0;
    cnt=0;
    for(j=0; j<N; j++){
      scanf("%d", &score[j]);
      sum += score[j];
    }
    average = (sum*1.0)/(N*1.0);
    for(j=0; j<N; j++){
      if(score[j] > average)
        cnt++;
    }
    percent=(cnt*1.0)/(N*1.0)*100.0;
    printf("%.3lf%%\n", percent);
  }
  return 0;
}

 

728x90