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 分钟前
蓝桥杯192.等差数列java
java·数据结构·算法·职场和发展·蓝桥杯
chase。11 分钟前
【学习笔记】从经典算法到通用神经运动规划器
笔记·学习·算法
2301_8101545512 分钟前
CVE-2019-6341 漏洞复现
java·开发语言
王璐WL16 分钟前
【C++】经典且易错的题
c++
feasibility.19 分钟前
OpenCV图像滤波算法应用:常见滤波器的原理与效果对比(含c++/python代码与中文显示)
c++·opencv·算法
老虎062720 分钟前
数据结构09(Java)-- 二分查找模板
java·开发语言·数据结构
蓝天星空21 分钟前
C#中for循环和foreach循环的区别
开发语言·c#
傻啦嘿哟24 分钟前
如何使用 Python 操作 Excel 图片:插入、提取与压缩
开发语言·python·excel
Rabitebla25 分钟前
快速排序(QuickSort)完全指南 —— 从原理到工业级优化
c语言·数据结构·c++·算法·github
赫瑞26 分钟前
Java中的图论2——Kruskal算法
java·算法·图论