백준 스터디

파푸·2022년 11월 13일

셀프 넘버 문제

#include<stdio.h>
int fun(int n){
    int tmp = n;
    while(n!=0){
        tmp += n % 10;
        n /= 10;
    }
    return tmp;
}
int main(){
    int a, i;
    int res[10001] = {0};
    for(i=0;i<10001;i++){
        a = fun(i);
        if(a < 10001) res[a]=1;
        if(!res[i]) printf("%d\n", i);
    }
    return 0;
}

-> 문제가 처음에 이해가 안돼서 고민했던 문제
생성자가 되는 수들은 배열에서 1로 표시해주고, 생성자가 아닌 배열 값이 0인 수들 출력

소수 찾기 문제

#include<stdio.h>
#pragma warning(disable:4996)
int main() {
	int n, i, j;
	int cnt, res=0;
	int count=0;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &cnt);
		res = 0;
		if (cnt <= 1) continue;
		for (j = 2; j < cnt; j++) {
			if (cnt % j == 0) {
				res++;
				break;
			}
		}
		if (res == 0) count++;
	}
	printf("%d", count);
}

-> 간단

그룹 단어 체커 문제

#include<stdio.h>
#include<string.h>
#pragma warning(disable:4996)
int main() {
	int n, i, j;
	int cnt=0;
	scanf("%d", &n);
	char str[101];
	for (i = 0; i < n; i++) {
		int eng[26] = { 0 };
		char start = '0';
		scanf("%s", str);
		for (j = 0; j < strlen(str); j++) {
			if (start != str[j]) {
				start = str[j];
				eng[str[j] - 'a'] += 1;
			}
			if ((eng[str[j] - 'a']) == 2) {
				cnt++;
				break;
			}
		}
	}
	printf("%d", n - cnt);
}

-> 만약 문자가 나오고 나서 연속되지 않은 상태로 한 번 더 나오게 되면 체크, 배열 인덱스를 만들고 'a'를 빼줘서 a=0, b=1 .... 이런 식으로 값을 넣어줬다.

크로아티아 알파벳

#include<stdio.h>
#include<string.h>
#pragma warning(disable:4996)
int main() {
	char str[101];
	int cnt, all, i;
	scanf("%s", str);
	cnt = strlen(str);
	all = strlen(str);
	for (i = 0; i < all; i++) {
		if (str[i] == '=') {
			if (str[i - 1] == 'c') cnt--;
			if (str[i - 1] == 's') cnt--;
			if (str[i - 1] == 'z') {
				cnt--;
				if (str[i - 2] == 'd') cnt--;
			}
		}
		if (str[i] == '-') {
			if (str[i - 1] == 'c') cnt--;
			if (str[i - 1] == 'd') cnt--;
		}
		if (str[i] == 'j') {
			if (str[i - 1] == 'l') cnt--;
			if (str[i - 1] == 'n') cnt--;
		}
	}
	printf("%d", cnt);
}

-> 문제만 이해하면 쉬운 문제, cnt를 빼주는 이유는, 2개의 알파벳이 1개의 알파벳을 이루는 경우가 있는데, 이 경우를 빼준 것이다.

profile
졸업하고싶다.

0개의 댓글