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;

}

相关推荐
火羽白麟2 分钟前
大坝安全的“大脑”——模型与算法
算法·模型·大坝安全
x70x804 分钟前
C++中auto的使用
开发语言·数据结构·c++·算法·深度优先
Han.miracle7 分钟前
数据结构与算法-012
java·开发语言
xu_yule9 分钟前
算法基础-单源最短路
c++·算法·单源最短路·bellman-ford算法·spfa算法
Evand J14 分钟前
【MATLAB免费例程】多无人机,集群多角度打击目标,时间与角度约束下的协同攻击算法,附下载链接
算法·matlab·无人机
智航GIS15 分钟前
2.1 变量与数据类型
开发语言·python
YGGP18 分钟前
【Golang】LeetCode 118. 杨辉三角
算法·leetcode
拼好饭和她皆失21 分钟前
c++---快速记忆stl容器
开发语言·c++
黎雁·泠崖25 分钟前
C 语言字符串高阶:strstr/strtok/strerror 精讲(含 strstr 模拟实现)
c语言·开发语言