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;

}

相关推荐
Y1rong1 小时前
C++ QT之记事本
开发语言·qt
Hcoco_me4 小时前
大模型面试题17:PCA算法详解及入门实操
算法
跨境卫士苏苏4 小时前
亚马逊AI广告革命:告别“猜心”,迎接“共创”时代
大数据·人工智能·算法·亚马逊·防关联
ZouZou老师5 小时前
C++设计模式之装饰器模式:以家具生产为例
c++·设计模式·装饰器模式
ZouZou老师5 小时前
C++设计模式之桥接模式:以家具生产为例
c++·设计模式·桥接模式
diegoXie5 小时前
Python / R 向量顺序分割与跨步分割
开发语言·python·r语言
程序员小白条5 小时前
0经验如何找实习?
java·开发语言·数据结构·数据库·链表
呱呱巨基5 小时前
Linux 进程概念
linux·c++·笔记·学习
liulilittle5 小时前
C++ 浮点数封装。
linux·服务器·开发语言·前端·网络·数据库·c++
云雾J视界5 小时前
当算法试图解决一切:技术解决方案主义的诱惑与陷阱
算法·google·bert·transformer·attention·算法治理