알고리즘

[알고리즘] 백준 13163 - 닉네임에 갓 붙이기 (C++)

blueberrysoda 2025. 3. 16. 23:45

[문제 링크] : https://www.acmicpc.net/problem/13163

#include <iostream>
using namespace std;

int main(){
    int T;
    cin >> T;
    cin.ignore();

    while(T--){
        string S, Ans="";
        int cnt = 0;
        cin.clear();

        getline(cin, S);

        for(int i=0; i<S.size(); i++){
            string tmp = "";
            int j = i;
            
            while(S[j] != ' ' && j != S.size()){
                tmp += S[j++];
            }
            
            i = j;
            
            if(cnt == 0){
                Ans += "god";
                cnt = 1;
                continue;
            }
            else{
                Ans += tmp;
            }
        }
        cout << Ans <<"\n";
    }
    return 0;
}