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;

}

相关推荐
minji...3 分钟前
Linux 网络套接字编程(一)端口号port,socket套接字,socket,bind,socket 通用结构体
linux·运维·服务器·开发语言·网络
2301_814809864 分钟前
踩坑实战pywebview:用 Python + Web 技术打造轻量级桌面应用
开发语言·前端·python
南境十里·墨染春水5 分钟前
C++流类库 字符串流
开发语言·c++
smj2302_796826526 分钟前
解决leetcode第3906题统计网格路径中好整数的数目
python·算法·leetcode
KobeSacre9 分钟前
leetcode 树
算法·leetcode·职场和发展
6Hzlia22 分钟前
【Hot 100 刷题计划】 LeetCode 104. 二叉树的最大深度 | C++ 自底向上递归最优解
算法
Robot_Nav22 分钟前
Kinodynamic Lazy ThetaStar:面向实时机器人导航的两阶段运动学路径规划算法
算法·机器人·lazy theta
weixin_5206498728 分钟前
C#线程底层原理知识
java·开发语言
AC赳赳老秦31 分钟前
OpenClaw与Excel联动:批量读取/写入数据,生成可视化报表
开发语言·python·excel·产品经理·策略模式·deepseek·openclaw