先用 cin.getline 讀取整行

再將字串丟入 stringstream

stringstream 會將字串一組一組輸出 (以空白為分界)

並將輸出的第一個字元減 32 ('a' = 97,  'A' = 65)

 

#include <iostream>
#include <sstream>

using namespace std;

int main()
{
    char input[301], name[10];
    stringstream ss;

    while(cin.getline(input, 300)){
        ss.clear();
        ss.str(input);

        while(ss >> name){
            name[0] -= 32;
            cout << name << endl;
        }
    }

    return 0;
}
 

arrow
arrow
    全站熱搜

    大神(偽) 發表在 痞客邦 留言(0) 人氣()