Broken Pad

Playing cards is an indispensable and irreplaceable activity for parties. In order to be more impartial and prevent magician YHH from cheating when shuffling cards, and give full play to his mind-reading advantages at the same time, psychologist ZH proposed to use a pad to play cards.

However, ZH found that the touch screen of the pad he was assigned was malfunctioning. Every time he clicked a card, this card and all the cards behind it would be selected. As we all know, the effect of choosing a card is equivalent to changing the state of the card, that is, if the card was initially selected, it would become unselected, and if it was unselected, it would become selected. Besides, there is another operation, which is to click on the blank space, so that all the cards will become unselected.

Now ZH needs to select some cards to play, but due to the malfunctioning of the touch screen, he cannot simply choose the cards he wants to choose. Now he has used the blind trick to secretly ask netizens which positions to click to choose the cards he wants, please help him!

Given two 01-strings a and b, which represent the current state of the card and the state required by ZH. 0 represents unselected, and 1 represents selected. Now you are asked to give a plan with the smallest number of tap times.

输入描述:

There are multiple test cases. The first line of input contains an integer T (1 ≤ T ≤ 10), indicating the number of test cases. For each test case:

The first line contains a string a (1 ≤ |a| ≤ 10510^5105), indicating the current state of the card.

The second line contains a string b (|b| = |a|), indicating the state required by ZH.

输出描述:

For each test case, print one line contains the minimum number of integers indicating the position ZH should tap in non-decreasing order.

Please note that number 0 is indicating the blank space, and it's guaranteed that the solution of all the test cases is unique.

示例1

输入

复制2 10110 10000 110101 000000

2
10110
10000
110101
000000

输出

复制3 5 0

3 5
0

说明

For the first sample, a is "10110", and b is "10000", then ZH needs first to tap the position 3 (based on 1) to make the state become "10001", and then tap the position 5 to make the state become "10000", so you should tell him 3 and 5.
#include <bits/stdc++.h>
using namespace std;

int main()
{
    char a[100010];
    char b[100010];
    int a1[100010];
    int b1[100010];
    int t;
    scanf("%d",&t);
    while(t--)
    {
       scanf("%s",a);
       scanf("%s",b);
       int n,m,i,j,k,l,f;
       k=l=0;
       f=0;
       int flag=0;
       n=strlen(a);
       for(i=0;i<n;i++)
       {
          if(b[i]!='0')
          {
             flag=1;
             break;
          }
       }
       if(flag==1)
       {

            for(i=0; i<n; i++)
            {
                if(a[i]!=b[i]&&f==0)
                {
                    a1[k]=i+1;
                    k++;
                    f=1;
                }
                else if(a[i]==b[i]&&f==1)
                {
                    a1[k]=i+1;
                    k++;
                    f=0;
                }
            }
            for(i=0;i<n;i++)
            {
               a[i]='0';
            }
            f=0;
            for(i=0; i<n; i++)
            {
                if(a[i]!=b[i]&&f==0)
                {
                    b1[l]=i+1;
                    l++;
                    f=1;
                }
                else if(a[i]==b[i]&&f==1)
                {
                    b1[l]=i+1;
                    l++;
                    f=0;
                }
            }
            if(k>l)
            {
                printf("0 ");
                for(i=0; i<l; i++)
                {
                    if(i==l-1)
                    {
                        printf("%d\n",b1[i]);
                    }
                    else
                    {
                        printf("%d ",b1[i]);
                    }
                }
            }
            else
            {
                for(i=0; i<k; i++)
                {
                    if(i==k-1)
                    {
                        printf("%d\n",a1[i]);
                    }
                    else
                    {
                        printf("%d ",a1[i]);
                    }
                }
            }
       }
       else
       {
          printf("0\n");
       }
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值