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;

}

相关推荐
阿正的梦工坊4 小时前
JavaScript 微任务与宏任务完全指南
开发语言·javascript·ecmascript
知行合一。。。4 小时前
Python--05--面向对象(属性,方法)
android·开发语言·python
自信150413057594 小时前
重生之从0开始学习c++之模板初级
c++·学习
leobertlan4 小时前
好玩系列:用20元实现快乐保存器
android·人工智能·算法
青梅橘子皮5 小时前
C语言---指针的应用以及一些面试题
c语言·开发语言·算法
浅时光_c5 小时前
3 shell脚本编程
linux·开发语言·bash
历程里程碑5 小时前
2. Git版本回退全攻略:轻松掌握代码时光机
大数据·c++·git·elasticsearch·搜索引擎·github·全文检索
极客智造5 小时前
深度解析 C++ 类继承与多态:面向对象编程的核心
c++
Evand J5 小时前
【三维轨迹目标定位,CKF+RTS,MATLAB程序】基于CKF与RTS平滑的三维非线性目标跟踪(距离+方位角+俯仰角)
开发语言·matlab·目标跟踪
_深海凉_6 小时前
LeetCode热题100-有效的括号
linux·算法·leetcode