2000
2016-03-27 13:21
155 查看
值得说明的是本程序只能实现输入一行打印一行
我没用弄明白:输入多组数据然后一起打印是怎么做到的?
参考c++版本
我没用弄明白:输入多组数据然后一起打印是怎么做到的?
#include <stdio.h> void myswap(char* a , char *b); int main(void) { char buffer[4]; while(gets(buffer)) { myswap(&buffer[0],&buffer[1]); myswap(&buffer[0],&buffer[2]); myswap(&buffer[1],&buffer[2]); printf("%c %c %c\n",buffer[0],buffer[1],buffer[2]); } return 0; } void myswap(char* a , char *b) { char c; if(*a > *b) {//a保存较小字符 c = *a; *a = *b; *b = c; } }
参考c++版本
#include <iostream> #include <algorithm> using namespace std; int main(void) { char n[4]; while (cin >> n) { if (n[0] > n[1]) swap(n[0], n[1]); if (n[1] > n[2]) swap(n[1], n[2]); if (n[0] > n[1]) swap(n[0], n[1]); cout << n[0] << ' ' << n[1] << ' ' << n[2] << endl; } return 0; }
相关文章推荐
- 《Linux 内核分析》第五周
- windows下mysql忘记root密码的解决方法
- 《Linux内核与分析》第五周
- jQuery选择器
- [BZOJ4134][JZOJ4401]ljw和lzr的hack比赛
- osx下配置qt开发环境
- C++中vector的用法
- ExpandableListView的实现
- 数组中将所有奇数排到偶数前面
- 杨辉三角 函数递归
- 第五章项目1——(3)三角形类雏形
- oracle常用函数
- 桶排序
- 感知哈希算法的opencv实现
- [MySQL] 参数: innodb_flush_log_at_trx_commit和sync_binlog
- 2.Utm-模块设计
- 理想团队模式及软件流程的理解
- servlet错误:HTTP Status 405 - HTTP method GET is not supported by this URL
- HDU-1166 敌兵布阵 ( 线段树 )
- 在JavaScript中创建命名空间的几种写法