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;

}

相关推荐
_codemonster1 分钟前
计算机视觉入门到实战系列(八)Harris角点检测算法
python·算法·计算机视觉
Snow_day.6 分钟前
有关排列排列组合(1)
数据结构·算法·贪心算法·动态规划·图论
随丶芯6 分钟前
IDEA安装leetcode-editor插件
java·开发语言
Ccjf酷儿20 分钟前
C++语言程序设计 (郑莉)第六章 数组、指针和字符串
开发语言·c++
禹曦a21 分钟前
Java实战:Spring Boot 构建电商订单管理系统RESTful API
java·开发语言·spring boot·后端·restful
superman超哥21 分钟前
精确大小迭代器(ExactSizeIterator):Rust性能优化的隐藏利器
开发语言·后端·rust·编程语言·rust性能优化·精确大小迭代器
芒克芒克21 分钟前
虚拟机类加载机制
java·开发语言·jvm
陌路2022 分钟前
C++28 STL容器--array
开发语言·c++
dora27 分钟前
【开发火星地平线辅助】智商不够,编程来凑
算法
im_AMBER30 分钟前
Leetcode 100 在链表中插入最大公约数
数据结构·c++·笔记·学习·算法·leetcode·链表