链接:https://ac.nowcoder.com/acm/contest/7591/B
来源:牛客网
题目描述
The party began, the greasy uncle was playing cards, the fat otaku was eating, and the little beauty was drawing.
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| ≤ 10^510
5
), 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
输出
复制
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;
vector<int>ans1,ans2;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
ans1.clear(),ans2.clear();
string s1,s2;int num1=0,num2=0;
cin>>s1>>s2;
//不清0.
for(int i=0;i<s1.size();i++)
{
if(num1&1)
{
if(s1[i]=='1') s1[i]='0';
else s1[i]='1';
}
if(s1[i]!=s2[i])
{
num1++;
ans1.push_back(i+1);
}
}
//清0.
ans2.push_back(0);
for(int i=0;i<s2.size();i++)
{
if(s2[i]!=('0'+(num2%2)))
{
num2++;
ans2.push_back(i+1);
}
}
if(ans2.size()<=ans1.size())//输出ans2.
{
for(int i=0;i<ans2.size();i++)
{
printf("%d ",ans2[i]);
}puts("");
}
else
{
for(int i=0;i<ans1.size();i++)
{
printf("%d ",ans1[i]);
}puts("");
}
}
return 0;
}