题意:问给出的字符串们的首字母是否相同(英文韵律)
思路:getline,stringstream。。。
#include <iostream>
#include <sstream>
using namespace std;
string line, word;
char head;
int flag;
int main()
{
while (true)
{
getline(cin, line);
if (line[0] == '*') break;
head = tolower(line[0]);
flag = true;
stringstream sin(line);
while (sin >> word)
{
if (tolower(word[0]) != head)
{
flag = false;
break;
}
}
cout << (flag?"Y":"N") << endl;
}
}
本文介绍了一个简单的程序,用于判断输入的多个英文单词是否拥有相同的首字母。通过使用C++标准库中的getline和stringstream,该程序能够逐个读取并比较每个单词的首字母。
155

被折叠的 条评论
为什么被折叠?



