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;

}

相关推荐
小辉同志34 分钟前
215. 数组中的第K个最大元素
数据结构·算法·leetcode··快速选择
小O的算法实验室1 小时前
2025年IEEE TITS,基于矩阵的进化计算+面向无线传感器网络数据收集无人机路径规划,深度解析+性能实测
算法·论文复现·智能算法·智能算法改进
kongba0071 小时前
项目打包 Python Flask 项目发布与打包专家 提示词V1.0
开发语言·python·flask
OidEncoder1 小时前
编码器分辨率与机械精度的关系
人工智能·算法·机器人·自动化
froginwe111 小时前
C 语言测验
开发语言
memcpy02 小时前
LeetCode 2615. 等值距离和【相同元素分组+前缀和;考虑距离和的增量】中等
算法·leetcode·职场和发展
极客智造2 小时前
深入详解 C++ 智能指针:RAII 原理、分类特性、底层机制与工程实战
c++·智能指针
今夕资源网2 小时前
powershell工具包 安装升级脚本并设置UTF-8 环境快捷方式创建 将powershell的编码默认改为UTF-8
开发语言·utf-8·powershell·utf-8编码·powershell7·powershell5·设置utf-8编码
炽烈小老头2 小时前
【 每天学习一点算法 2026/04/22】四数相加 II
学习·算法
alphaTao2 小时前
LeetCode 每日一题 2026/4/20-2026/4/26
算法·leetcode·职场和发展