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;

}

相关推荐
YYYing.14 小时前
【C++项目之高并发内存池 (三)】万字解析CentralCache与PageCache的初步实现
c++·笔记·哈希算法·高并发·c/c++·内存池
李少兄14 小时前
解决 java.net.ConnectException: Connection refused 报错
java·开发语言·.net
gumichef14 小时前
栈和队列(1)
开发语言·数据结构
小新同学^O^14 小时前
算法学习 --> 快速输入和输出
java·学习·算法
脑子加油站14 小时前
K8S-Ingress资源对象
算法·贪心算法·k8s
2601_9534656114 小时前
纯前端高性能!m3u8live.cn 重新定义 M3U8 在线播放与调试体验
开发语言·前端·javascript·m3u8
Chase_______14 小时前
【算法】LeetCode 1052 & 3679:定长滑动窗口进阶——增益最大化与频率约束贪心
算法·leetcode
天若有情67314 小时前
从零搭建局域网手机遥控电脑网页项目,吃透工程化与架构设计思维
服务器·前端·数据库·算法·开源·node·工程化
凯瑟琳.奥古斯特14 小时前
力扣1367:二叉树中查找链表路径
数据结构·算法·leetcode·链表
云天AI实战派14 小时前
Python 智能体实战:从 0 搭建模块化 Agent 路由系统,落地小龙虾门店运营助手
开发语言·人工智能·python