CodeForces - 752B
CodeForces - 752B
https://vjudge.net/problem/597648/origin
简单模拟,主要是细节
特殊情况多考虑一下,看代码就行
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<set>
#include<map>
#include<stack>
#include<cstring>
#define inf 2147483647
#define ls rt<<1
#define rs rt<<1|1
#define lson ls,nl,mid,l,r
#define rson rs,mid+1,nr,l,r
#define N 100010
#define For(i,a,b) for(int i=a;i<=b;i++)
#define p(a) putchar(a)
#define g() getchar() using namespace std;
char c1[N],c2[N];
int n,a[N],cnt;
bool b[N];
void in(int &x){
int y=;
char c=g();x=;
while(c<''||c>''){
if(c=='-')y=-;
c=g();
}
while(c<=''&&c>=''){
x=(x<<)+(x<<)+c-'';c=g();
}
x*=y;
}
void o(int x){
if(x<){
p('-');
x=-x;
}
if(x>)o(x/);
p(x%+'');
}
int main(){
cin>>(c1+)>>(c2+);
n=strlen(c1+);
For(i,,n){
if(c1[i]==c2[i]&&!a[(int)c1[i]]){
a[(int)c1[i]]=(int)c1[i];
}
else
if(c1[i]!=c2[i]&&!a[(int)c1[i]]&&!a[(int)c2[i]]){
a[(int)c1[i]]=(int)c2[i];
a[(int)c2[i]]=(int)c1[i];
cnt++;
}
else
if(c1[i]!=c2[i]&&(a[(int)c1[i]]!=(int)c2[i]||a[(int)c2[i]]!=(int)c1[i])){
o(-);
return ;
}
else
if(c1[i]==c2[i]&&a[(int)c1[i]]!=(int)c1[i]){
o(-);
return ;
}
}
o(cnt);p('\n');
For(i,,n){
if(c1[i]!=c2[i]&&!b[c1[i]]){
p(c1[i]);p(' ');p(c2[i]);p('\n');
b[c1[i]]=b[c2[i]]=;
}
}
return ;
}
CodeForces - 752B的更多相关文章
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
- CodeForces - 148D Bag of mice
http://codeforces.com/problemset/problem/148/D 题目大意: 原来袋子里有w只白鼠和b只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...
随机推荐
- Altera FPGA– Bit Slip
通过在接收端加延时,在延时间隙插入'0'或'1',以使最终接收和期望数据一致. BitSlip操作要注意几点: 1,BitSlip操作在rx_bitslip的上升沿即开始: 2,BitSlip操作开始 ...
- 2019/11/1 CSP模拟
写在前面的反思 该拿的部分分还是得拿完啊,因为懒+动作慢没有写最后一道题的菊花图和链的情况,其实这两个点并不难.. 虽然只有\(10pts\),但是已经足够往上爬一截了啊,额外的\(10pts\)在今 ...
- (20)Oracle函数
substr 截取字段 substr(字符串,截取开始位置,截取长度) substr(str,n,m) 第二,三参数可以省略, 第二个参数为负数时表示从倒数第n位开始向后截取m个 round(str, ...
- Spring Cloud Config的配置中心使用非对称性加密
首先,我们需要通过keytool工具来生成密钥对. keytool是JDK中的一个密钥和证书管理工具.它使用户能够管理自己的公钥/私钥对及相关证书,用于(通过数字签名)自我认证(用户向别的用户/服务认 ...
- 菲波那切数列(Fibonacci Number)
什么是菲波那切数列?自己google一下,面试题里面经常遇到,考试递归算法用的. 在菲波那切数列中用递归不太好.第三种算法最好. 第一 递归算法最差了,不想说.测试一下,当N=6000时,半天出不来数 ...
- 18-3-bind
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- SpringCloud学习笔记《---02 Eureka ---》篇
- 【默默努力】react-drag-grid
先放项目地址:https://github.com/Bilif/react-drag-grid 项目运行效果 感谢无私开源的程序员 先看项目入口文件 //index.js import React f ...
- Widget Factory
Widget Factory 有N种零件,生产所需天数都为3~9天,有M条记录,记录开工星期几,和停工星期几,并告诉你这条记录所加工的零件,求每种零件的生产时间,\(1≤N,M≤300\). 解 显然 ...
- 【Codeforces Round #424 (Div. 2) D】Office Keys
[Link]:http://codeforces.com/contest/831/problem/D [Description] 有n个人,它们都要去一个终点,终点位于p; 但是,在去终点之前,他们都 ...