http://codeforces.com/contest/752/problem/B

uuu

yyu

xy

xx

注意变化了之后,检查一次前面已经变化过的就好。因为可能前面的满足,但是变了后不满足。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string> const int maxn = 1e3 + ;
struct node {
char x, y;
node(char xx, char yy) {
if (xx > yy) {
swap(xx, yy);
}
x = xx;
y = yy;
}
bool operator < (const struct node & rhs) const {
if (x != rhs.x) return x < rhs.x;
else return y < rhs.y;
}
};
set<struct node>ans;
char str[maxn];
char sub[maxn];
char book[maxn];
bool vis[maxn];
void work() {
memset(book, '$', sizeof book);
cin >> str + ;
cin >> sub + ;
for (int i = ; sub[i]; ++i) book[sub[i]] = sub[i];
for (int i = ; str[i]; ++i) {
if (str[i] != book[sub[i]]) {
char ch = book[sub[i]];
book[book[sub[i]]] = str[i];
book[str[i]] = ch;
ans.insert(node(str[i], sub[i]));
for (int j = ; j <= i; ++j) {
if (str[j] != book[sub[j]]) {
// cout << i << endl;
cout << - << endl;
return;
}
}
}
}
cout << ans.size() << endl;
for (set<struct node> :: iterator it = ans.begin(); it != ans.end(); ++it) {
cout << it->x << " " << it->y << endl;
}
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
work();
return ;
}

B. Santa Claus and Keyboard Check 模拟的更多相关文章

  1. Codeforces 784B Santa Claus and Keyboard Check

    题面: 传送门 B. Santa Claus and Keyboard Check Input file: standard input Output file: standard output Time ...

  2. Codeforces Round #389 Div.2 B. Santa Claus and Keyboard Check

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  3. CodeForces - 748B Santa Claus and Keyboard Check

    题意:给定两个字符串a和b,问有多少种不同的字母组合对,使得将这些字母对替换字符串b后,可以变成字符串a.注意字母对彼此各不相同. 分析:vis[u]记录与u可形成关系的字母,若u与v不同,则形成字母 ...

  4. codeforces 748E Santa Claus and Tangerines

    E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  5. Codeforces Round #389 Div.2 C. Santa Claus and Robot

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  6. Codeforces Round #389 Div.2 A. Santa Claus and a Place in a Class

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  7. Santa Claus and Tangerines

    Santa Claus and Tangerines 题目链接:http://codeforces.com/contest/752/problem/E 二分 显然直接求答案并不是很容易,于是我们将其转 ...

  8. E. Santa Claus and Tangerines

    E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  9. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) D. Santa Claus and a Palindrome STL

    D. Santa Claus and a Palindrome time limit per test 2 seconds memory limit per test 256 megabytes in ...

随机推荐

  1. POJ-1743 Musical Theme(后缀数组)

    题目大意:给一个整数序列,找出最长的连续变化相同的.至少出现两次并且不相重叠一个子序列. 题目分析:二分枚举长度进行判定. 代码如下: # include<iostream> # incl ...

  2. cvMat结构体详解

    /* *CvMat矩阵头 */ typedef struct CvMat { int type; //数据类型,比如CV_32FC1含义是32位浮点型单通道,再比如CV_8UC3含义是8位无符号整型三 ...

  3. [solr] - 环境搭建

    这里忽略java安装和tomcat安装,这里使用的是solr-4.10.0 1.到apache下载solr,地址: http://mirrors.hust.edu.cn/apache/lucene/s ...

  4. bzoj3087: Coci2009 misolovke

    Description [misolovke]给定一个 N*N 的网格.每个格子里至少会有一个捕鼠器, 并且已知每个格子里的捕鼠器个数.现在需要在 每一行 中选取恰好 K 个连续的格子, 把里面的捕鼠 ...

  5. 黄聪:详解 ManualResetEvent(转)

    原文:http://www.cnblogs.com/li-peng/p/3291306.html 今天详细说一下ManualResetEvent 它可以通知一个或多个正在等待的线程已发生事件,允许线程 ...

  6. php数据库访问

    从$res获取行数据的时候,处理mysql_fetch_row($res),还有三个方法,分别是 mysql_fetch_row($res); 返回一个所以的数组,速度较快. mysql_fetch_ ...

  7. Python-Tkinter几何布局管理(转)

    所有的Tkinter组件都包含专用的几何管理方法,这些方法是用来组织和管理整个父配件区中子配件的布局的.Tkinter提供了截然不同的三种几何管理类:pack.grid和place. pack() p ...

  8. delphi 常用的将窗口置前的函数

    function BringWindowToTopEx(hWnd: HWND): Boolean;begin if IsIconic(hWnd) then ShowWindow(hWnd, SW_RE ...

  9. (DP)3.Longest Substring Without Repeating Characters

    Given a string, find the length of the longest substring without repeating characters. For example, ...

  10. JDBC进行批处理

    转自 http://mousepc.iteye.com/blog/1131462 业务场景:当需要向数据库发送一批SQL语句执行时,应避免向数据库一条条的发送执行,而应采用JDBC的批处理机制,以提升 ...