1.题目描述:

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.

Input Specification:

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∣ ≤ 105), indicating the current state of the card.

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

Output Specification:

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.

Sample Input:

2
10110
10000
110101
000000

结尾无空行

Sample Output:

3 5
0

结尾无空行

Hint:

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.

2.代码展示:

#include<bits/stdc++.h>
using namespace std;
const int MAX=1e5+5;
//用于计算操作数
int cal(string s1,string s2,int c[]){
int count1=0,num=0;
int flag=1;//用于标记状态是否改变
for(int i=0;s1[i];i++){
//如果此时片初始状态和终止状态不同,且卡片初始状态未改变
if((s1[i]!=s2[i])&&flag){
c[num++]=i+1;//存储操作过程
count1++;//统计操作数
flag=0;//改变状态
}
//如果此时片初始状态和终止状态相同,且卡片初始状态改变
else if(!flag&&(s1[i]==s2[i])){
c[num++]=i+1;//存储操作过程
count1++;//统计操作数
flag=1;//改变状态
}
}
return count1;
}
int main(){
int T;//T为测试用例的数量
cin>>T;
while(T--){
string s1,s2,s3;
int a[MAX],b[MAX];
cin>>s1>>s2;
s3=s1;
int count1=0,count2=0;
//1.按清零操作
for(int i=0;s1[i];i++)s1[i]='0';//将卡片初始状态全部清零
count1++;//操作数加1
count1=cal(s1,s2,a);//进行操作数的计算
//2.不按清零操作
count2=cal(s3,s2,b);//进行操作数的计算 //进行操作数的计算
//比较清零与不清零的操作数,看看谁是最小值
if(count1<count2){
cout<<"0";
for(int i=0;i<count1;i++)cout<<" "<<a[i];
}else {
for(int i=0;i<count2;i++){
if(i==count2-1)cout<<b[i];
else cout<<b[i]<<" ";
}
}
cout<<endl;
}
return 0;
}

原题链接:PTA | 程序设计类实验辅助教学平台

7-2 Broken Pad (20 分)的更多相关文章

  1. 【PAT甲级】1084 Broken Keyboard (20 分)

    题意: 输入两行字符串,输出第一行有而第二行没有的字符(对大小写不敏感且全部以大写输出). AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #inclu ...

  2. 1084 Broken Keyboard (20 分)

    1084 Broken Keyboard (20 分) On a broken keyboard, some of the keys are worn out. So when you type so ...

  3. pat 1084 Broken Keyboard(20 分)

    1084 Broken Keyboard(20 分) On a broken keyboard, some of the keys are worn out. So when you type som ...

  4. 1112 Stucked Keyboard (20 分)

    1112 Stucked Keyboard (20 分) On a broken keyboard, some of the keys are always stucked. So when you ...

  5. 【刷题-PAT】A1112 Stucked Keyboard (20 分)

    1112 Stucked Keyboard (20 分) On a broken keyboard, some of the keys are always stucked. So when you ...

  6. 抛弃EF,20分构建一个属于自己的ORM框架

    Poiuyt_cyc 博客园首页新随笔联系订阅管理随笔 - 11  文章 - 0  评论 - 111 抛弃EF,20分构建一个属于自己的ORM框架 相信EF大家都不陌生了,因为数据库表跟程序实体是一一 ...

  7. PTA 邻接表存储图的广度优先遍历(20 分)

    6-2 邻接表存储图的广度优先遍历(20 分) 试实现邻接表存储图的广度优先遍历. 函数接口定义: void BFS ( LGraph Graph, Vertex S, void (*Visit)(V ...

  8. #020PAT 没整明白的题L1-009 N个数求和 (20 分)

    后面的测试点过不去,两个错误一个超时. 目前未解决   L1-009 N个数求和 (20 分)   本题的要求很简单,就是求N个数字的和.麻烦的是,这些数字是以有理数分子/分母的形式给出的,你输出的和 ...

  9. L1-023 输出GPLT (20 分)

    L1-023 输出GPLT (20 分) 给定一个长度不超过10000的.仅由英文字母构成的字符串.请将字符重新调整顺序,按GPLTGPLT....这样的顺序输出,并忽略其它字符.当然,四种字符(不区 ...

  10. PAT 乙级 1074 宇宙无敌加法器 (20 分)

    1074 宇宙无敌加法器 (20 分) 地球人习惯使用十进制数,并且默认一个数字的每一位都是十进制的.而在 PAT 星人开挂的世界里,每个数字的每一位都是不同进制的,这种神奇的数字称为“PAT数”.每 ...

随机推荐

  1. 自用nodejs安装笔记

    下载Nodejs 进入Nodejs官网https://nodejs.org/zh-cn/ 下载 安装Node.js 检查Nodejs和npm包管理器是否安装成功 用管理员打开cmd控制台 命令行输入n ...

  2. 【个人首测】百度文心一言 VS ChatGPT GPT-4

    昨天我写了一篇文章GPT-4牛是牛,但这几天先别急,文中我测试了用GPT-4回答ChatGPT 3.5 和 Notion AI的问题,大家期待的图片输入也没有出现. 昨天下午百度发布了文心一言,对标C ...

  3. 孙勇男:实时视频 SDK 黑盒测试架构丨Dev for Dev 专栏

    Dev for Dev 专栏全称为 Developer for Developer,该专栏是声网与 RTC 开发者社区共同发起的开发者互动创新实践活动.透过工程师视角的技术分享.交流碰撞.项目共建等多 ...

  4. 声网Agora发布教育信息化解决方案 助力教育公平提效

    4月23日-25日,由中国教育装备行业协会主办的第79届教育装备展在厦门国际会展中心举办.作为赋能教育信息化的实时互动PaaS服务商,声网Agora应邀参会.展会现场,声网展示了基于实时音视频互动能力 ...

  5. axios和后端交互时,参数需要写在body和query中同时写

    axios.post('/api/xxx',{ // post body },{ params: { // query } }) demo: let params = { _id:this.alarm ...

  6. [nefu]算法设计与分析-锐格实验

    谈点个人感想:锐格这个题目和数据要是再不维护,估计直接就裂开了,跪求学校升级改进一下OJ系统和题目Orz 实验一 递归与分治 6104 #include<bits/stdc++.h> us ...

  7. MySQL相关优质文章推荐

    MySQL相关优质文章推荐 文章推荐 文章链接地址 MySQL高性能优化系列 MySQL字符集及校对规则的理解 MySQL InnoDB锁机制全面解析分享 MySQL事务隔离级别和MVCC,MVCC文 ...

  8. 【Jenkins系列】-Pipeline语法全集

    Jenkins为您提供了两种开发管道代码的方式:脚本式和声明式. 脚本式流水线(也称为"传统"流水线)基于Groovy作为其特定于域的语言. 而声明式流水线提供了简化且更友好的语法 ...

  9. Flutter 异步编程指南

    作者:京东物流 王志明 1 Dart 中的事件循环模型 在 App 开发中,经常会遇到处理异步任务的场景,如网络请求.读写文件等.Android.iOS 使用的是多线程,而在 Flutter 中为单线 ...

  10. 线性规划的单纯形法—R实现

    table { margin: auto } 线性规划的单纯形法 线性规划是运筹学中的一个基本分支,它广泛应用现有的科学技术和数学方法,解决实际中的问题,帮助决策人员选择最优方针和决策,自1947年丹 ...