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;

}

相关推荐
慢慢向上的蜗牛18 小时前
Atlas300I推理卡驱动适配Linux 6.12+内核
linux·c++·人工智能·华为·驱动·底层开发·ascend
50万马克的面包18 小时前
C语言第3讲:分支和循环
c语言·开发语言·笔记·算法
ytttr87318 小时前
惯性导航精解算程序(MATLAB实现)
开发语言·matlab
艺杯羹18 小时前
从零搭建CSDN博客爬虫:Python爬虫+多格式导出完整教程
开发语言·爬虫·python·开源·gui·csdn
码农小韩18 小时前
QT学习记录(三)——C++学习基础(三)
开发语言·c++·qt·学习·算法·嵌入式软件
buhuizhiyuci18 小时前
【QT-百日筑基篇】找寻安静的落脚处,选择合适的功法进行修炼-QT深度了解对象树的特性
开发语言·qt
wjs202418 小时前
jQuery Mobile 触摸事件详解
开发语言
承渊政道18 小时前
【动态规划算法】(似包非包以及卡特兰数问题深入解析)
数据结构·c++·学习·算法·leetcode·动态规划·哈希算法
kyriewen1118 小时前
你的前端滤镜慢得像PPT?用Rust+WebAssembly,一秒处理4K图
开发语言·前端·javascript·设计模式·rust·ecmascript·powerpoint