Sequential game
Sequential game
Problem Description
When comes a character , it
must compare with the rightmost one of sequence, if it's the same with the
coming characters ,the coming one just join the string. Most the right side.
Otherwise all the characters in the sequence must change its value, 0 to 1 and 1
to 0,then the coming one add to its right side. Here is an example, if there is
a sequence '110' when comes a character 0,the sequence become '1100' at last, if
comes a character 1,the sequence become '0011' at last.
It's very difficult
for HeroWei to play the game. Can you help him?
Input
input is ended by EOF.
Output
descripted above.Output a line contains two integers ,which are the number of 0s
and 1s in the sequence after the game.
Sample Input
0
110
1111
1010
Sample Output
1 0
3 0
0 4
4 0 [Tips]
For example ,1010: 1->00->111->0000
描述:
题目大意,有一个01的字符流。当 第 i 个字符和第 i-1 个字符不同时,就把前 i-1个字符,每一个字符都改变一下,如果是0就变为1,如果是1就变为0. 当第 i 个字符和第 i-1个字符一样的时候,就什么事都不发生。对于110, 则是
1->11->000. 然后问你,有多少个0, 多少个1. 这问题就有点简单了啊,很容易可以发现,其实只有两种可能,要么全 0, 要么全 1。我们只要记录 这个字符流中字符 1 的 个数。和字符 0 的个数,然后记录最后一个字符就可以了。
如果这个字符流中只有一种字符,那么结果显而易见的。如果都有,那么就全部变成最后一次出现的那个字符,不信的话,自己随手写一个字符流,去推一推,我就是这么发现的规律。
#include<bits/stdc++.h> using namespace std; const int N = ; int main() {
char str[N];
while (cin >> str) {
int len_str = strlen(str);
int sum_1 = , sum_0 = ;
for (int i = ; i < len_str; i++) {
if (str[i] == '') sum_1++;
if (str[i] == '') sum_0++;
if (sum_1 != && sum_0 != ) break;
}
if (sum_1 != && sum_0 != ) {
if (str[len_str - ] == '') {
printf("%d %d\n", , len_str);
} else {
printf("%d %d\n", len_str, );
}
} else {
if (sum_1 == ) printf("%d %d\n", len_str, );
else printf("%d %d\n", , len_str);
}
}
return ;
}
Sequential game的更多相关文章
- Creating a SharePoint Sequential Workflow
https://msdn.microsoft.com/en-us/library/office/hh824675(v=office.14).aspx Creating a SharePoint Seq ...
- Sequential List
Sequential ListSequential list storage structure:#define LIST_INIT_SIZE 20 #define LIST_INCREASE 10t ...
- Support Vector Machine (2) : Sequential Minimal Optimization
目录 Support Vector Machine (1) : 简单SVM原理 Support Vector Machine (2) : Sequential Minimal Optimization ...
- completed solution matches microsoft sequential workflow tutorial
microsoft sequential workflow tutorial website:http://msdn.microsoft.com/en-us/library/ms734794(v=vs ...
- Time Series data 与 sequential data 的区别
It is important to note the distinction between time series and sequential data. In both cases, the ...
- Java中的查找算法之顺序查找(Sequential Search)
Java中的查找算法之顺序查找(Sequential Search) 神话丿小王子的博客主页 a) 原理:顺序查找就是按顺序从头到尾依次往下查找,找到数据,则提前结束查找,找不到便一直查找下去,直到数 ...
- Loadrunner中参数化实战(1)-Sequential+Each iteration
参数化数据30条: 脚本如下,演示登录,投资,退出操作是,打印手机号: 首先验证Vugen中迭代: Sequential+Each iteration 设置迭代4次Action 结果如下:
- Sequential Read Ahead For SQL Server
Balancing CPU and I/O throughput is essential to achieve good overall performance and to maximize ha ...
- control file sequential read 等待事件
可能的原因 control file sequential read Reading from the control file. This happens in many cases. For ex ...
- sequential minimal optimization,SMO for SVM, (MATLAB code)
function model = SMOforSVM(X, y, C ) %sequential minimal optimization,SMO tol = 0.001; maxIters = 30 ...
随机推荐
- Java——静态类型 实际类型
public class test { static class father { void run() { System.out.println("father run"); } ...
- 虚拟机安装 Output error file to the following location
有的用户会对你中安装虚拟机系统,但偶尔会在安装过程中遇到一些问题.比如在电脑安装虚拟机系统时出现提示“Output error file to the following location”,这一般是 ...
- 选择vim编辑器的7个理由
当我刚刚开始用 vi 文本编辑器的时候,我讨厌它!我认为这是有史以来设计上最痛苦和反人类的编辑器.但我还是决定我必须学会它,因为如果你使用的是 Unix,vi 无处不在并且是唯一一个保证你可以使用的编 ...
- 多module project修改module名称
1.mvn clean 2.project 去掉这个module 3.全局替换所有pom.xml文件的老module名为新module名 4.修改源代码文件夹目录名为新的module名 5.proje ...
- 记ubuntu sudo无法使用,su密码不对的解决办法
前言 因为我有强制关机的习惯, 然后就杯具了.. ubuntu版本是 16.04 sudo没法使用, su密码不对, 顿时我就慌了 解决方案 1.1.开机点击ESC,进去GUN GRUB界面 1.2. ...
- DVWA--CSP Bypass
0x01看到标题,是否有点疑惑 CPS 是什么东东.简单介绍一下就是浏览器的安全策略,如果 标签,或者是服务器中返回 HTTP 头中有 Content-Security-Policy 标签 ,浏览器会 ...
- java跨越请求实例
使用Access-Control-Allow-Origin解决跨域 什么是跨域 当两个域具有相同的协议(如http), 相同的端口(如80),相同的host(如www.google.com),那么我们 ...
- 《Effective Java》读书笔记 - 8.通用编程
Chapter 8 General Programming Item 45: Minimize the scope of local variables local variables应该在他们要被用 ...
- 每日踩坑 2019-07-30 H5 使用 iframe 底部有白边
用个iframe累死累活的 用 js 动态计算高度, 结果明明px都对,然后却把页面滚动条也整出来了. 查看元素盒模型也一切正常. 然后仔细观察就发现是下边多了几个像素的白色边. 然后就 百度呗 以下 ...
- 五大主流数字币钱包:imToken数字货币钱包,Bitcoin core钱包,BTS网页版钱包,AToken轻钱包,Blockchain
AToken数字货币钱包 超容易上手支持五大主流币种 互联网 | 编辑: 王静涛 2017-12-28 09:58:33转载 国家监管部门已叫停数字货币交易,包括火币网.比特币中国.OKC ...