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;

}

相关推荐
W.A委员会2 小时前
JS原型链详解
开发语言·javascript·原型模式
止语Lab3 小时前
Go并发编程实战:Channel 还是 Mutex?一个场景驱动的选择框架
开发语言·后端·golang
她说彩礼65万3 小时前
C# 实现简单的日志打印
开发语言·javascript·c#
绿浪19843 小时前
c# 中结构体 的定义字符串字段(性能优化)
开发语言·c#
房开民3 小时前
可变参数模板
java·开发语言·算法
t***5444 小时前
如何在现代C++中更有效地应用这些模式
java·开发语言·c++
不知名的忻4 小时前
Morris遍历(力扣第99题)
java·算法·leetcode·morris遍历
状元岐4 小时前
C#反射从入门到精通
java·javascript·算法
itman3014 小时前
C语言、C++与C#深度研究:从底层到现代开发演进全解析
c语言·c++·c·内存管理·编译模型
_深海凉_5 小时前
LeetCode热题100-除了自身以外数组的乘积
数据结构·算法·leetcode