Sequential game

Problem Description

Sequential detector is a very important device in Hardware experiments. But is very difficult for many students such as HeroWei. In nearest days, his teacher Miss Fang let him simulate sequence detector. But there many sequence here ,and Miss Fang add the difficulty that when she give HeroWei a sequence and a string ,you must tell her how many string here in this sequence. But now Miss Fang simplified the problem for HeroWei, she just give Herowei a sequence and let HeroWei play a game with it.
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

Each line contains a composed by a string of 0s and 1s.the
input is ended by EOF.

Output

For each given sequence you just play with this string as
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的更多相关文章

  1. Creating a SharePoint Sequential Workflow

    https://msdn.microsoft.com/en-us/library/office/hh824675(v=office.14).aspx Creating a SharePoint Seq ...

  2. Sequential List

    Sequential ListSequential list storage structure:#define LIST_INIT_SIZE 20 #define LIST_INCREASE 10t ...

  3. Support Vector Machine (2) : Sequential Minimal Optimization

    目录 Support Vector Machine (1) : 简单SVM原理 Support Vector Machine (2) : Sequential Minimal Optimization ...

  4. completed solution matches microsoft sequential workflow tutorial

    microsoft sequential workflow tutorial website:http://msdn.microsoft.com/en-us/library/ms734794(v=vs ...

  5. Time Series data 与 sequential data 的区别

    It is important to note the distinction between time series and sequential data. In both cases, the ...

  6. Java中的查找算法之顺序查找(Sequential Search)

    Java中的查找算法之顺序查找(Sequential Search) 神话丿小王子的博客主页 a) 原理:顺序查找就是按顺序从头到尾依次往下查找,找到数据,则提前结束查找,找不到便一直查找下去,直到数 ...

  7. Loadrunner中参数化实战(1)-Sequential+Each iteration

    参数化数据30条: 脚本如下,演示登录,投资,退出操作是,打印手机号: 首先验证Vugen中迭代: Sequential+Each iteration 设置迭代4次Action 结果如下:

  8. Sequential Read Ahead For SQL Server

    Balancing CPU and I/O throughput is essential to achieve good overall performance and to maximize ha ...

  9. control file sequential read 等待事件

    可能的原因 control file sequential read Reading from the control file. This happens in many cases. For ex ...

  10. sequential minimal optimization,SMO for SVM, (MATLAB code)

    function model = SMOforSVM(X, y, C ) %sequential minimal optimization,SMO tol = 0.001; maxIters = 30 ...

随机推荐

  1. c++string int转化简单写法

    #include<iostream> #include<string> #include<sstream> //定义了stringstream类 using nam ...

  2. jackson 完整Jar包

    Jackson fasterxml和codehaus的区别: 他们是Jackson的两大分支.也是两个版本的不同包名.Jackson从2.0开始改用新的包名fasterxml: 1.x版本的包名是co ...

  3. 对ECMAScript的研究-----------引用

    ECMAScript 新特性与标准提案 一:ES 模块 第一个要介绍的 ES 模块,由于历史上 JavaScript 没有提供模块系统,在远古时期我们常用多个 script 标签将代码进行人工隔离.但 ...

  4. Mysql 连接路径 url 参数解析

    1.mysql - url 参数解析 url:jdbc:mysql://127.0.0.1:3306/user?useUnicode=true&characterEncoding=utf8 u ...

  5. BZOJ 4245: [ONTAK2015]OR-XOR 贪心 + 位运算

    Description 给定一个长度为n的序列a[1],a[2],...,a[n],请将它划分为m段连续的区间,设第i段的费用c[i]为该段内所有数字的异或和,则总费用为c[1] or c[2] or ...

  6. 序列式容器————forward_list

    单链表的形式存储元素.forward_list 的模板定义在头文件 forward_list 中.fdrward_list 和 list 最主要的区别是:它不能反向遍历元素:只能从头到尾遍历. for ...

  7. 【canvas学习笔记八】像素操作

    ImageData对象 ImageData对象包含了一个区域内的canvas的像素信息.它包含以下可读属性: width canvas的宽度,单位是像素. height canvas的高度,单位是像素 ...

  8. 自定义springmvc参数解析器

    实现spring HandlerMethodArgumentResolver接口 通过使用@JsonArg自定义注解来解析json数据(通过fastjson的jsonPath),支持多个参数(@Req ...

  9. 说下Java堆空间结构,及常用的jvm内存分析命令和工具

    Java堆空间结构图:http://www.cnblogs.com/SaraMoring/p/5713732.html JVM内存状况查看方法和分析工具: http://blog.csdn.net/n ...

  10. leetcode-mid-math -171. Excel Sheet Column Number

    mycode   90.39% class Solution(object): def titleToNumber(self, s): """ :type s: str ...