C++ 截取字符串比大小 朴灿烈づ我的快乐病毒、 2022-04-16 06:45 228阅读 0赞 输入一串字符: I study ver hard.C++ language is very interesting.She is a teacher. 以 . 分割 比大小 输出: C++ language is very interesting. I study ver hard. She is a teacher. #include<iostream> #include<cstring> using namespace std; int main(){ string ss,s[4]; getline(cin,ss); int len=ss.size(); int n=0; for(int i=0;i<len;i++){ if(ss[i]!='.') s[n]+=ss[i]; else{ s[n]+='.'; n++; } } if(s[1]>s[2]) swap(s[1],s[2]); if(s[3]<s[1]) swap(s[1],s[3]); if(s[3]<s[2]) swap(s[2],s[3]); cout<<s[1]<<endl; cout<<s[2]<<endl; cout<<s[3]<<endl; return 0; }
还没有评论,来说两句吧...