9093

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

int main(void){
    // 테스트 케이스 개수 입력
    int test_case = 0;
    scanf("%d", &test_case);
    getchar(); // 버퍼 비우기 (\n)

    for(int i = 0; i < test_case; i++){
        // 문장 입력
        char str[1001]={0};
        gets(str);

        int start = -1;
        int len = strlen(str);
        str[len] = 32;
        for(int i = 0; i <= len; i++){
            // start가 -1이고 현재 값이 공백이 아닐 경우
            if((start == -1)&&(str[i] != 32)){
                // start를 현재 인덱스로 변경
                start = i;
            }

            // 현재값이 공백일 경우
            if((str[i] == 32)){
                // i-1 부터 start까지 출력 (단어 뒤집어서)
                for(int j = (i-1); j >= start; j--){
                    printf("%c", str[j]);
                }
                printf(" ");
                
                // start 초기화
                start = -1;
            }
        }

        printf("\n");
    }
    
    return 0;
}

'백준' 카테고리의 다른 글

[ 백준 / C ] 9012번 : 괄호  (0) 2025.11.25
[ 백준 / C ] 5948번 : Bad Random Numbers  (0) 2025.11.24
[ 백준 / C ] 10828번 : 스택  (0) 2025.11.21
[ 백준 / C ] 5635번 : 생일  (0) 2025.11.20
[ 백준 / C ] 10845번 : 큐  (0) 2025.11.19

+ Recent posts