题目链接:点击查看

题目大意:给出两个字符串s和t,两个字符串中相同的字母可以匹配,问号可以和任意字符匹配,现在问两个字符串最多能匹配多少个字符,并给出匹配的下标

题目分析:挺好玩的一道水题,大体思路就是先遍历一遍两个字符串,将所有的字符下标都分类储存起来,按照以下顺序匹配:

  1. s串和t串中的普通字母
  2. s串的问号和t串中的普通字母
  3. t串的问号和s串中的普通字母
  4. s串的问号和t串中的问号

按照上面的顺序暴力就可以了

代码:

#include<iostream>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cctype>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<set>
#include<map>
#include<sstream>
#include<unordered_map>
using namespace std;typedef long long LL;const int inf=0x3f3f3f3f;const int N=2e5+100;int main()
{
//  freopen("input.txt","r",stdin);
//    ios::sync_with_stdio(false);int n;string a,b;cin>>n>>a>>b;vector<int>aa[27];//0~25储存字母,26储存问号vector<int>bb[27];vector<pair<int,int>>ans;for(int i=0;i<a.size();i++){if(a[i]=='?')aa[26].push_back(i+1);elseaa[a[i]-'a'].push_back(i+1);}for(int i=0;i<b.size();i++){if(b[i]=='?')bb[26].push_back(i+1);elsebb[b[i]-'a'].push_back(i+1);}for(int i=0;i<26;i++)//优先匹配字母{while(aa[i].size()&&bb[i].size()){ans.push_back(make_pair(aa[i].back(),bb[i].back()));aa[i].pop_back();bb[i].pop_back();}}if(aa[26].size())//匹配a中的问号{for(int i=0;i<26;i++){while(aa[26].size()&&bb[i].size()){ans.push_back(make_pair(aa[26].back(),bb[i].back()));aa[26].pop_back();bb[i].pop_back();}    }}if(bb[26].size())//匹配b中的问号{for(int i=0;i<26;i++){while(bb[26].size()&&aa[i].size()){ans.push_back(make_pair(aa[i].back(),bb[26].back()));aa[i].pop_back();bb[26].pop_back();}   }}while(aa[26].size()&&bb[26].size())//匹配两个串中的问号{ans.push_back(make_pair(aa[26].back(),bb[26].back()));aa[26].pop_back();bb[26].pop_back();}cout<<ans.size()<<endl;for(int i=0;i<ans.size();i++)printf("%d %d\n",ans[i].first,ans[i].second);return 0;
}

CodeForces - 1141D Colored Boots(暴力+水题)相关推荐

  1. Codeforces 864 A Fair Game 水题

    题目链接: http://codeforces.com/problemset/problem/864/A 题目描述: 看不是是不是一串数中只有两种数且这两种数字的数量是相同的 解题思路: 水题, 水过 ...

  2. 【CodeForces - 569B】Inventory (水题)

    题干: Companies always have a lot of equipment, furniture and other things. All of them should be trac ...

  3. codeforces 702A A. Maximum Increase(水题)

    题目链接: A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input sta ...

  4. CodeForces - 1287B Hyperset(暴力水题)

    题目链接:点击查看 题目大意:给出"集合"的定义: 集合中必须有三个元素 每个元素的每个特征值必须全部相同或者全部不同,不能存在两者相同但与第三者不同 现在给出n个元素以及m个特征 ...

  5. Codeforces gym 100685 C. Cinderella 水题

    C. Cinderella Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/ ...

  6. codeforces 667A A. Pouring Rain(水题)

    题目链接: A. Pouring Rain time limit per test 1 second memory limit per test 256 megabytes input standar ...

  7. 【CodeForces - 485A】Factory (水题,抽屉原理,tricks)

    题干: One industrial factory is reforming working plan. The director suggested to set a mythical detai ...

  8. CodeForces - 25A IQ test【水题】

    题目链接:https://codeforces.com/contest/25/problem/A #include <iostream> using namespace std; int ...

  9. CodeForces - 29A Spit Problem【水题】

    题目链接:https://codeforces.com/contest/29/problem/A #include <iostream> #include <cstdio> # ...

最新文章

  1. C语言 找数码是否存在
  2. gradle编译出错:Execution failed for task #39;:app:compileTestDebugJava#39;.
  3. 北斗导航 | Modified Tropospheric:对流层延迟计算(matlab代码)
  4. 图像数据格式基础知识
  5. sdut 区间覆盖问题
  6. mysql被除数为0不报错_MySQL:关系除法
  7. (71)FPGA时钟双沿约束如何做?
  8. 50. Pow(x, n) (MATH)
  9. 大数据是普惠金融的未来!
  10. Vue 3 + Vite + Eslint + prettier + husky + lint-staged 搭建基础项目
  11. 我的linux系统怎么输入pv,如何在Linux系统中使用pv命令
  12. 怎么做手游性能测试?
  13. 矩阵变换器MATLAB仿真,其他仿真模型也可 图中为三相矩阵 变换器仿真模型及其输入输出电流波形
  14. Linux磁盘热插拔命令
  15. 嵌入式软件开发学习 工程师要掌握的基本技能
  16. P2P网络认识与实践
  17. 基于FPGA的任意信号发生器
  18. 做城市规划设计,如何下载地形图?
  19. Proxy与Object.defineProperty的优劣对比
  20. 【最新版】一款容易吸粉的盲盒抽奖小程序源码

热门文章

  1. 给用户权限数据添加缓存
  2. SpringSecurity 权限控制之异常处理流程图
  3. 执行SQL-MapperProxy.invoke()
  4. 为什么要用MyBatis-Spring JDBC
  5. 自定义线程池-java内置线程池构造方法介绍
  6. Java 扫描并加载包路径下class文件
  7. 选择结构_穿透的switch语句
  8. Collection集合常用功能
  9. 如何禁用单个FegionClient的Hystrix的支持
  10. Ribbon-3使用配置文件自定义Ribbon Client