9/8 (회의 불참)

chi·2024년 9월 8일

백준

목록 보기
16/20

10987

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

int main() {
    char word[101];
    scanf("%s", word);

    int count = 0;
    int length = strlen(word);

    for (int i = 0; i < length; i++) {
        if (word[i] == 'a' || word[i] == 'e' || word[i] == 'i' || word[i] == 'o' || word[i] == 'u') {
            count++;
        }
    }

    printf("%d\n", count); 

    return 0;
}

반복문을 사용하여 입력된 단어의 각 문자를 하나씩 확인해 해당 문자가 aeiou중 하나인 경우 모음의 개수를 세는 변수 count를 1씩 증가시킨다

10953

#include <stdio.h>

int main() {
    int T; 
    scanf("%d", &T); 

    for (int i = 0; i < T; i++) {
        int A, B;
        scanf("%d,%d", &A, &B);
        printf("%d\n", A + B);
    }

    return 0;
}

테스트 케이스의 개수 T 입력
이후 for문으로 T번 반복하면서 각 테스트 케이스에서 두 정수 A와 B를 입력받음
이때 두 정수는 콤마로 구분되므로 scanf의 형식을 "%d,%d"로 설정해 콤마를 기준으로 두 정수를 입력받는다
각 테스트 케이스에서 입력된 두 정수의 합을 계산하여 바로 출력한다

2953

#include <stdio.h>

int main() {
    int scores[5][4];
    int total[5] = {0};
    int maxScore = 0;
    int winner = 0;

    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 4; j++) {
            scanf("%d", &scores[i][j]);
            total[i] += scores[i][j];
        }
    }

    for (int i = 0; i < 5; i++) {
        if (total[i] > maxScore) {
            maxScore = total[i];
            winner = i + 1;
        }
    }

    printf("%d %d\n", winner, maxScore);

    return 0;
}

scores[5][4] 배열을 이용하여 5명의 참가자 각각의 4개 평가 점수를 저장
total[5] 배열을 이용하여 각 참가자의 총점을 계산
각 참가자의 점수는 scanf()로 입력받으며 동시에 total[i]에 더해 총점을 계산
총점이 가장 큰 참가자를 찾기 위해 maxScore에 현재까지의 최대 점수를 저장
total[i] 값이 maxScore보다 크면 해당 점수를 maxScore에 저장하고 우승자 번호 갱신 참가자의 번호는 1번부터 시작하므로 배열 인덱스에 1을 더함

0개의 댓글