ZCMU-1463-Sequential game

1463: Sequential game

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 119   Solved: 84
[ Submit][ Status][ Web Board]

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

【解析】
题意就是让我们输入一个字符串,我拿样例四举个例子吧,输入了1010,在输入第二个的时候输入的是0,只要是前面
和0不一样的都变成1,第三个输入的是1,只要是前面和1不一样的都变成1,,最后一个输入的是0只要和0不一样的都变
成0。我们会发现其实我们只需要判断最后一个是什么就可以了,前面一定会全部改变和最后一个一样的数。
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
    string s;
    int i,p,j;
    while(cin>>s)
    {
        p=s.size();
       if(s[p-1]=='0')
       {
        printf("%d %d\n",p,0);
       }
       else
       {
           printf("%d %d\n",0,p);
       }
    }
  return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值