C++——输入3个字符串,按由小到大的顺序输出。用指针或引用方法处理。

没注释的源代码

#include <iostream>

#include <string>

#include <stdio.h>

using namespace std;

void swap(string&str1,string&str2);

int main()

{

string a=" ",

b=" ",

c=" ";

char *p1=&a[0],*p2=&b[0],*p3=&c[0];

cout<<"please input line p1,p2,p3:"<<endl;

gets(p1);

gets(p2);

gets(p3);

if(a>b) swap(a,b);

if(a>c) swap(a,c);

if(b>c) swap(b,c);

cout<<"now the order is:"<<endl<<a<<endl<<b<<endl<<c<<endl;

return 0;

}

void swap(string&str1,string&str2)

{

string temp;

temp=str1;

str1=str2;

str2=temp;

}

相关推荐
阿里加多1 小时前
第 4 章:Go 线程模型——GMP 深度解析
java·开发语言·后端·golang
likerhood2 小时前
java中`==`和`.equals()`区别
java·开发语言·python
IronMurphy2 小时前
【算法三十九】994. 腐烂的橘子
算法
zs宝来了2 小时前
AQS详解
java·开发语言·jvm
Ares-Wang3 小时前
算法》》旅行商问题 TSP、7座桥问题 哈密顿回路 深度优先 和 宽度优先
算法·深度优先·宽度优先
Liqiuyue3 小时前
Transformer:现代AI革命背后的核心模型
人工智能·算法·机器学习
WolfGang0073213 小时前
代码随想录算法训练营 Day34 | 动态规划 part07
算法·动态规划
telllong3 小时前
Python异步编程从入门到不懵:asyncio实战踩坑7连发
开发语言·python
And_Ii3 小时前
LCR 168. 丑数
c++
Kk.08024 小时前
Linux(十一)fork实例练习、文件操作示例及相关面试题目分享
linux·运维·算法