CSU
来源:互联网 发布:onavo protect mac版 编辑:程序博客网 时间:2024/06/18 10:30
1、2、3三个数字组成的序列,要求把所有的2放在前面,所有的3放在后面,输出结果。
Input
每组数据1、2、3组成的一行字符串,长度不超过10 ^ 5。
Output
把原串的2放在前面,3放在后面,输出。
Sample Input
12321
223311
Sample Output
22113
221133
Hint
[分析]
常见的思路就是遍历记录每个数字的个数,然后按顺序输出。这里就不再赘述。
然后分享一个杀马特操作。
用sort(其实也不是很厉害,就是开拓一下思维,顺便更好地学习一下sort)。
自定义一个cmp
根据cmp的特性:如果cmp返回true,就说明前一个变量的优先级更高
不过这样写其实时间效率不是很高,这里只是为了开拓思维。
[代码]
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;bool cmp(char a, char b){ if (a == '2'&&b == '1')return 1; if (a == '2'&&b == '3')return 1; if (a == '1'&&b == '3')return 1; return 0;}int main(){ int arr[4]; char a[100005]; while (scanf("%s", a) != EOF) { int len = strlen(a); sort(a, a + len, cmp); printf("%s\n", a); }}
阅读全文
0 0
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- 接口限流算法总结
- 非wifi网络用户选择图片加载模式
- 集合---- Set (1)
- Linux Device Tree
- Statement、Preparestatement和CallableStatement
- CSU
- Linux -- 第一部分 shell
- 程序员面试笔试宝典
- hdu 1846 基础巴什博奕
- spring中scope(作用越)理解
- spring boot 配置
- HDU-6069 Counting Divisors
- Spring-2 <p: >标签的使用
- java 内部类 局部类 细节