B.Sequential Game

Description

Sequential detector is a very important device in Hardware experiments. But it 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 gave HeroWei a sequence and a string, he must tell her how many strings here in this sequence. But now Miss Fang simplified the problem for HeroWei, she just gave Herowei a sequence and let HeroWei play a game with it.

When a character comes, it must compare with the last one of sequence, if it's the same with the last one, the coming one should join into the string and become the last one of the sequence. 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' and comes a character 0, the sequence becomes '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



————————————————————

#include <iostream>
#include <stdio.h>
#include <string.h>
#define maxn 50000 + 10


using namespace std;


int main(void)
{   bool num[maxn];
    char str[maxn];
    while(scanf("%s", str) != EOF)
    {   int num0 = 0;
        int num1 = 0;
        int len = strlen(str);
        for(int i = 0; i <len; i++)
           num[i] = str[i] - '0';
        for( int i = 1; i < len ; i++)
        {
            if(num[i] != num[i-1])
            {
              for(int j = 0; j < i; j++)
                  num[j] =! num[j];
            }


        }


        for( int i = 0; i < len ; i++)
         {
             if(num[i])
               num1++;
             else
               num0++;
         }
        printf("%d %d\n",num0,num1);
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值