NOI / 1.7编程基础之字符串 11:潜伏者

#include 
#include 

using namespace std;

char A[26]={ '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
bool check(char c[])
{
	for (int i = 0; i < 26; i++)
	{
		if (A[i] < 'A' || A[i]>'Z')return false;
	}
	for (int i = 0; i < 26; i++)
	{
		for (int j = i + 1; j < 26; j++)
		{
			if (c[i] == c[j])return false;
		}
	}
	return true;
}

int main() 
{
	string a,b,s;
	int i;
	cin >> a>> b >> s;
	bool flag = true;
	for (i = 0; i < b.size(); i++)
	{
		if (A[a[i] - 'A'] != '0' && A[a[i] - 'A'] != b[i])
		{
			flag = false;
			break;
		}
		A[a[i] - 'A'] = b[i];
	}
	if(! check(A))flag = false;
	if(flag)
	{
		for (i = 0; i < s.length(); i++)
		{
			cout << A[s[i] - 'A'];
		}
	}
	else cout << "Failed";
	return 0;
}

你可能感兴趣的:(c++)