登 录
#include<iostream> #include<string> #include<cstdlib> using namespace std; int main() { string str="中华人名共和国 北京 五星红旗 义勇军进行曲"; string str_temp=""; str_temp.assign(str); string result[4]={"","","",""}; int position=0; for(int i=0;i<3;i++) { position=str_temp.find(" "); result[i]=str_temp.substr(0,position); str_temp=str_temp.substr(position+1,str_temp.length()-position); } result[3]=str_temp; cout<<"国家:"<<result[0]<<endl; cout<<"首都:"<<result[1]<<endl; cout<<"国旗:"<<result[2]<<endl; cout<<"国歌:"<<result[3]<<endl; str_temp.swap(result[0]); for(int j=1;j<4;j++) { str_temp+=" "; str_temp.append(result[j]); } int equal=str.compare(str_temp); if(equal==0) { cout<<"字符串相同,匹配成功!"<<endl; } else cout<<"字符串不相同,匹配不成功!"<<endl;
//cout<<str_temp<<endl; return EXIT_SUCCESS; }
抱歉!评论已关闭.