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;

}

相关推荐
科雷软件测试3 小时前
Python中itertools.product:快速生成笛卡尔积
开发语言·python
OOJO4 小时前
c++---list介绍
c语言·开发语言·数据结构·c++·算法·list
别或许5 小时前
1、高数----函数极限与连续(知识总结)
算法
田梓燊5 小时前
code 560
数据结构·算法·哈希算法
笨笨饿6 小时前
29_Z变换在工程中的实际意义
c语言·开发语言·人工智能·单片机·mcu·算法·机器人
kobesdu6 小时前
综合强度信息的激光雷达去拖尾算法解析和源码实现
算法·机器人·ros·slam·激光雷达
艾为电子6 小时前
【技术帖】让接口不再短命:艾为 C-Shielding™ Type-C智能水汽防护技术解析
c语言·开发语言
weixin_413063216 小时前
记录 MeshFlow-Online-Video-Stabilization 在线稳像
算法·meshflow·实时防抖
会编程的土豆6 小时前
【数据结构与算法】动态规划
数据结构·c++·算法·leetcode·代理模式
棉花骑士6 小时前
【AI Agent】面向 Java 工程师的Claude Code Harness 学习指南
java·开发语言