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;

}

相关推荐
感哥6 小时前
C++ 多态
c++
沐怡旸13 小时前
【底层机制】std::string 解决的痛点?是什么?怎么实现的?怎么正确用?
c++·面试
NAGNIP13 小时前
大模型框架性能优化策略:延迟、吞吐量与成本权衡
算法
美团技术团队14 小时前
LongCat-Flash:如何使用 SGLang 部署美团 Agentic 模型
人工智能·算法
River41616 小时前
Javer 学 c++(十三):引用篇
c++·后端
感哥18 小时前
C++ std::set
c++
Fanxt_Ja19 小时前
【LeetCode】算法详解#15 ---环形链表II
数据结构·算法·leetcode·链表
侃侃_天下19 小时前
最终的信号类
开发语言·c++·算法
茉莉玫瑰花茶19 小时前
算法 --- 字符串
算法
博笙困了19 小时前
AcWing学习——差分
c++·算法