SWEA/[D1]

[C언어] SWEA 2047 신문 헤드라인

ruming 2022. 3. 2. 01:47

주어지는 문자열의 알파벳 소문자를 모두 대문자로 바꾼다.

문자열의 최대 길이는 80bytes이다.

 

[예제]

The_headline_is_the_text_indicating_the_nature_of_the_article_below_it.

THE_HEADLINE_IS_THE_TEXT_INDICATING_THE_NATURE_OF_THE_ARTICLE_BELOW_IT.

 

#include <stdio.h>
#include <string.h>
int main() {
    char c[81] = {0};
    gets(c);
    int i;
    for(i=0; i<strlen(c); i++){
        if(c[i]>=97&&c[i]<=122){	//if(c[i] >= 'a' && c[i] <= 'z'){
            c[i] -= 32;
        }
    }
    puts(c);
    return 0;
}

소문자의 아스키코드는 97부터이다. 아스키코드로 소문자를 확인한 뒤('a'도 가능하다) 32만큼 빼주면 대문자로 변환된다.