스키마에듀 0318 백준문제

2023. 3. 15. 14:24스키마에듀 c언어 수업

728x90

 

https://www.acmicpc.net/problem/1110

 

1110번: 더하기 사이클

0보다 크거나 같고, 99보다 작거나 같은 정수가 주어질 때 다음과 같은 연산을 할 수 있다. 먼저 주어진 수가 10보다 작다면 앞에 0을 붙여 두 자리 수로 만들고, 각 자리의 숫자를 더한다. 그 다음,

www.acmicpc.net

 

#include <stdio.h>

int main(void){
  int n, new_num, origin, cnt = 0;
  int x1, x2=0;
  
  scanf("%d", &n);
  origin = n; // 맨 처음에 들어온 값

  while(1){
    x1 = n/10;
    x2 = n%10;
    new_num = x1 + x2;
    n = x2*10 + new_num%10;
    cnt++;
    
    //printf("%d\n",n);

    if(origin == n){
      break;
    }
  }
  printf("%d\n", cnt);

  return 0;
}

 

https://www.acmicpc.net/problem/10103

 

10103번: 주사위 게임

첫 라운드는 상덕이의 승리이다. 따라서 창영이는 6점을 잃게 된다. 두 번째 라운드는 두 사람의 숫자가 같기 때문에, 아무도 점수를 잃지 않고 넘어간다. 세 번째 라운드의 승자는 창영이이기

www.acmicpc.net

 

#include <stdio.h>

int main(void){
  
  int n, i, x, y;
  int stu1=100, stu2 = 100;
  scanf("%d", &n);

  for(i=0;i<n;i++){
    scanf("%d %d", &x, &y);
    if(x<y){
      stu1 -= y;
    }else if(x>y){
      stu2 -= x;
    }
  }

  printf("%d\n", stu1);
  printf("%d\n", stu2);
  return 0;
}

 

 

1316번: 그룹 단어 체커

그룹 단어란 단어에 존재하는 모든 문자에 대해서, 각 문자가 연속해서 나타나는 경우만을 말한다. 예를 들면, ccazzzzbb는 c, a, z, b가 모두 연속해서 나타나고, kin도 k, i, n이 연속해서 나타나기 때

www.acmicpc.net

 

#include <stdio.h>
#include <string.h>

int check(char * w){
  int i, j;
  for(i=0;i<strlen(w);i++){
    for(j=i+1; j<strlen(w); j++){
      if(w[i]==w[j]){
        if(w[j] != w[j-1]){
          return -1; // 그룹단어가 아님!
        }
      }
    }
  }
  return 0;
}

int main(void){

  int n=0;
  scanf("%d", &n); //단어개수
  int result = n; // 그룹단어 개수. 초기값은 n
  int i;

  for(i=0;i<n;i++){
    char word[101] = {0};
    scanf("%s", word);
    if(check(word)== -1){ //그룹단어가 아니면
      result --; //전체 단어개수에서 제외
    }    
  }
  printf("%d\n", result);
  return 0;
}