string操作
来源:互联网 发布:如何连接网络打印机 编辑:程序博客网 时间:2024/04/27 16:43
题目描述:把一个字符串只含有0和1,求把这个串排成非递减次序的串的最少的步数
输入:
4
01
10
110
11010
输出:
0
1
1
2
#include<iostream>#include<algorithm>#include<string>using namespace std;int main(){int n;cin >> n;while (n--){string tmp;cin >> tmp;int s = 0;int cnt = 0;int e = tmp.length() - 1;while (s < e){while (tmp[s] == '0'&&s<e)s++;while (tmp[e] == '1'&&s < e)e--;if (s < e){cnt++;char c = tmp[s];tmp[s] = tmp[e];tmp[e] = c;s++;e--;}}cout << cnt << endl;}return 0;}
阅读全文
0 0
- string 操作
- string操作
- String 操作
- String操作
- string操作
- String操作
- String操作
- String操作
- String操作
- string操作
- String操作
- string操作
- String操作
- string操作、文件操作
- String 清晰了解String操作
- string----------只适用于string操作
- Spring RedisTemplate操作-String操作
- 对String的操作
- poj 2352 Stars
- 多态的相关知识
- pandas中style输出格式
- spring02
- Android WebView 运行在系统进程引发的异常
- string操作
- win7+python3.6+word_cloud 安装出现Microsoft Visual C++ 14.0 is required
- crontab定时任务
- 突击战(Commando War,UVA 11792)
- 9.makefile的学习
- (学习java)没有头结点的单链表
- HTML5 内容模型类别以及html元素
- C语言的翻译环境(编译+链接)
- 2. Add Two Numbers