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;

}

相关推荐
0 0 02 小时前
CCF-CSP 39-2 水印检查(watermark)【C++】
c++·算法
plus4s2 小时前
2月15日(78,80,81题)
c++·算法·图论
能源系统预测和优化研究2 小时前
【原创改进代码】考虑碳交易与电网交互波动惩罚的共享储能电站优化配置与调度模型
算法·能源
935962 小时前
机考27 翻译21 单词14
c语言·数据结构·算法
光泽雨3 小时前
C# 中 Assembly 类详解
开发语言·c#
少控科技3 小时前
C#基础训练营 - 02 - 运算器
开发语言·c#
Riemann~~4 小时前
C语言嵌入式风格
c语言·开发语言
回敲代码的猴子4 小时前
2月14日打卡
算法
blackicexs4 小时前
第四周第七天
算法
期末考复习中,蓝桥杯都没时间学了5 小时前
力扣刷题19
算法·leetcode·职场和发展