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;

}

相关推荐
Dlrb12111 小时前
C语言-指针三
c语言·算法·指针·const·命令行参数
kkeeper~2 小时前
0基础C语言积跬步之深入理解指针(5下)
c语言·开发语言
Tisfy2 小时前
LeetCode 2540.最小公共值:双指针(O(m+n))
算法·leetcode·题解·双指针
一直不明飞行2 小时前
Java的equals(),hashCode()应该在什么时候重写
java·开发语言·jvm
IronMurphy2 小时前
【算法四十七】152. 乘积最大子数组
算法
REDcker2 小时前
有限状态机与状态模式详解 FSM建模Java状态模式与C++表驱动模板实践
java·c++·状态模式
盲敲代码的阿豪2 小时前
Python 入门基础教程(爬虫前置版)
开发语言·爬虫·python
basketball6162 小时前
C++ 构造函数完全指南:从入门到进阶
java·开发语言·c++
互联科技报3 小时前
2026超融合选型:Top5品牌与市场格局解读
开发语言·perl
weixin199701080163 小时前
[特殊字符] 智能数据采集:数字化转型的“数据石油勘探队”(附Python实战源码)
开发语言·python