Submission details
Task:Swapping letters
Sender:dsedov
Submission time:2018-09-15 15:58:19 +0300
Language:C++
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.01 sdetails
#2ACCEPTED0.01 sdetails
#3ACCEPTED0.01 sdetails
#4ACCEPTED0.09 sdetails
#5ACCEPTED0.06 sdetails
#6--details
#7ACCEPTED0.39 sdetails
#8ACCEPTED0.06 sdetails
#9ACCEPTED0.06 sdetails
#10ACCEPTED0.06 sdetails

Code

#include <stdio.h>
#include <iostream>
#include <memory.h>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

#define sqr(a) ((a) * (a))
#define pi 3.1415926535897932384626433832795

//#define TASK "d"

int n, a;
string c1, c2;
char f[326][2];

void Load()
{
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> f[i][0] >> f[i][1];
	cin >> c1 >> c2;
}

void Solve()
{
	if (c1.length() != c2.length())
	{
		cout << "NO";
		return;
	}
	int len = c1.length();

	for(int i = 0; i < n; i++)
	{
		
		int l = 0, r = 0;
		//bool ok = true;
		while(l < len && r < len)
		{
			while((c1[l] != f[i][0] && c1[l] != f[i][1]) && l < len)
				l++;
			
			while((c2[r] != f[i][0] && c2[r] != f[i][1]) && r < len)
				r++;
			
			if(c1[l] != c2[r])
			{
		//		cerr << c1[l] << " " << c2[r] << endl;
				cout << "NO";
				return;	
			}
			l++;
			r++;
		}

		while((c1[l] != f[i][0] && c1[l] != f[i][1]) && l < len)
				l++;
		while((c2[r] != f[i][0] && c2[r] != f[i][1]) && r < len)
				r++;

		if (l != r)
		{
			cout << "NO";
			return;
		}
	}

	cout << "YES";
}

int main()
{
//	freopen(TASK".in", "r", stdin);
//	freopen(TASK".out", "w", stdout);
	
	Load();
	Solve();

	return 0;
}

Test details

Test 1

Verdict: ACCEPTED

input
5
a b
b c
c d
d e
...

correct output
YES

user output
YES

Test 2

Verdict: ACCEPTED

input
2
a b
b c
acbbaca
cabbaac

correct output
YES

user output
YES

Test 3

Verdict: ACCEPTED

input
2
a b
b c
acbbaca
baccaab

correct output
NO

user output
NO

Test 4

Verdict: ACCEPTED

input
10
d c
e b
f y
h q
...

correct output
YES

user output
YES

Test 5

Verdict: ACCEPTED

input
10
a i
a l
d a
g h
...

correct output
NO

user output
NO

Test 6

Verdict:

input
325
a b
a e
a f
a g
...

correct output
YES

user output
(empty)

Test 7

Verdict: ACCEPTED

input
325
a c
a e
a g
a h
...

correct output
NO

user output
NO

Test 8

Verdict: ACCEPTED

input
0
dlkinfmdyjaofxbccwhhbxzartqwdr...

correct output
YES

user output
YES

Test 9

Verdict: ACCEPTED

input
0
bxisdrdpgcsnnvhnfgimivzqpqjwqc...

correct output
NO

user output
NO

Test 10

Verdict: ACCEPTED

input
0
mrwduerojcguvxzmbomfsainvqehsl...

correct output
NO

user output
NO