输入3个字符串,将它们按照字母由大到小排序(示例代码)
我们可以用string方法定义字符串变量。以下是具体实现代码。需要的朋友可以过来参考下,希望对大家有所帮助
用string方法定义字符串变量
实现代码:
代码如下:
#include<iostream>
#include<string>
using namespace std;
int main(){
string a,b,c,t;
cout<<"please input first string:"<<endl;
cin>>a;
cout<<"please input second string:"<<endl;
cin>>b;
cout<<"please input third string:"<<endl;
cin>>c;
if(a>b){
t=a;
a=b;
b=t;
}
if(a>c){
t=a;
a=c;
c=t;
}
if(b>c){
t=b;
b=c;
c=t;
}
cout<<a<<"<<"<<b<<"<<"<<c<<endl;
return 0;
}
精彩图集
精彩文章