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;

}

相关推荐
大大杰哥8 小时前
leetcode hot100(4)矩阵
算法·leetcode·矩阵
Fuyo_11198 小时前
C++中的活字印刷术——模板·初阶
开发语言·c++·笔记
小白|8 小时前
cmake:昇腾CANN构建系统完全指南
java·c++·算法
在角落发呆8 小时前
跨越网络鸿沟:传统文件传输与现代内网穿透的奇妙交响
开发语言·php
nebula-AI8 小时前
人工智能导论:模型与算法(未来发展与趋势)
人工智能·神经网络·算法·机器学习·量子计算·automl·类脑计算
王老师青少年编程8 小时前
2026年全国青少年信息素养大赛“算法应用主题赛”(初赛)【C++考点大纲】(全场景、组别):文末附备考秘籍!
c++·全国青少年信息素养大赛·初赛·2026年·算法应用主题赛·考点大纲
炽烈小老头8 小时前
【每天学习一点算法 2026/05/21】课程表
学习·算法
Season4508 小时前
C++之模板元编程(前置知识 constexpr)
开发语言·c++
luoganttcc8 小时前
大模型是否即将到达算法极限
算法
AI玫瑰助手8 小时前
Python运算符:比较运算符(等于不等等于大于小于)与返回值
android·开发语言·python