C++ Primer(第5版) 练习 5.21
练习 5.21 修改5.5.1节(第171页)练习题的程序,使其找到的重复单词必须以大写字母开头。
环境:Linux Ubuntu(云服务器)
工具:vim
代码块
/*************************************************************************> File Name: ex5.20.cpp> Author: > Mail: > Created Time: Mon 12 Feb 2024 04:18:53 PM CST************************************************************************/#include<iostream>
#include<string>
#include<vector>
using namespace std;int main(){vector<string> str;string s;while(cin>>s){str.push_back(s);}int upper = 0;int sign = 0;string temp;for(auto beg : str){if(beg[0] >= 'A' && beg[0] <= 'Z' && upper == 0){temp = beg;upper = 1;continue;}else if(beg[0] >= 'a' && beg[0] <= 'z'){upper = 0;continue;}if(beg == temp && upper == 1){sign = 1;break;}}if(sign == 1){cout<<"The word is "<<temp<<endl;}else{cout<<"No word is repeated continuously."<<endl;}return 0;
}