龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > C/C++开发 >

输入3个字符串,将它们按照字母由大到小排序(示例代码)

时间:2014-05-16 15:32来源:网络整理 作者:网络 点击:
分享到:
我们可以用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; 
}

收藏文章
表情删除后不可恢复,是否删除
取消
确定
图片正在上传,请稍后...
评论内容为空!
还没有评论,快来抢沙发吧!

热评话题

按钮 内容不能为空!
立刻说两句吧! 查看0条评论
精彩图集

赞助商链接