标签:
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<math.h>
using namespace std;
char l1[] = {"ZZZ9999"};
char l2[] = {"BBBBB00"};
char temp[] = {"BDEFGHJKLNOQRSTUVWXYZ"};
char error[] = {"ACMPI"};
long long ask(char a[], char b[])
{
long long sum = 0, suma = 0, sumb = 0;
if (a[3]>=‘0‘ && a[3]<=‘9‘ && b[3]>=‘0‘ && b[3]<=‘9‘)
{
for (int i=0; i<3; ++i)
{
suma += (a[i]-‘A‘)*pow(26, 2-i);
cout << 2-i << "==" << pow(26, 2-i) << endl;
}
suma *= 10000;
for (int i=3; i<7; ++i)
{
suma += (a[i]-‘0‘)*pow(10, 6-i);
}
for (int i=0; i<3; ++i)
{
sumb += (b[i]-‘A‘)*pow(26, 2-i);
}
sumb *= 10000;
for (int i=3; i<7; ++i)
{
sumb += (b[i]-‘0‘)*pow(10, 6-i);
}
sum = suma - sumb; // 传参时 a[]是SM b[]是SI.
}
else if (a[3]>=‘A‘ && a[3]<=‘Z‘ && b[3]>=‘A‘ && b[3]<=‘Z‘)
{
for (int i=0; i<5; ++i)
{
int tempc;
for (int j=0; j<21; ++j)
{
if (a[i] == temp[j])
{
tempc = j;
//cout << tempc << "----\n";
break;
}
}
suma += tempc*pow(21, 4-i);
}
suma *= 100;
suma += (a[5]-‘0‘)*10 + (a[6]-‘0‘);
for (int i=0; i<5; ++i)
{
int tempc;
for (int j=0; j<21; ++j)
{
if (b[i] == temp[j])
{
tempc = j;
// cout << tempc << "----\n";
break;
}
}
sumb += tempc*pow(21, 4-i);
}
sumb *= 100;
sumb += (b[5]-‘0‘)*10 + (b[6]-‘0‘);
sum = suma - sumb;
}
else
{
suma = ask(a, l2);
sumb = ask(l1, b);
sum = suma + sumb + 1;
}
return sum;
}
int check(char s[])
{
bool ok1 = true;
bool ok2 = true;
if (s[3]>=‘A‘ && s[3]<=‘Z‘)
{
for (int i=0; i<5; ++i)
{
for (int j=0; j<5; ++j)
{
if (s[i] == error[j])
{
return 0;
}
}
}
}
for (int i=0; i<3; ++i)
{
if (s[i]<‘A‘ || s[i]>‘Z‘)
{
ok1 = false;
break;
}
}
for (int i=3; i<7; ++i)
{
if (s[i]<‘0‘ || s[i]>‘9‘)
{
ok1 = false;
break;
}
}
for (int i=0; i<5; ++i)
{
if (s[i]<‘A‘ || s[i]>‘Z‘)
{
ok2 = false;
break;
}
}
for (int i=5; i<7; ++i)
{
if (s[i]<‘0‘ || s[i]>‘9‘)
{
ok2 = false;
break;
}
}
if (ok1) return 1;
if (ok2) return 2;
return 0;
}
int main()
{
long long int c;
char sm[10], si[10];
while(cin >> sm >> si >> c)
{
if (sm[0] == ‘*‘ && si[0] == ‘*‘ && c == 0)
break;
if (!check(si))
{
cout << "N\n";
continue;
}
long long ans = ask(si, sm);
if (ans>0 && ans<=c)
{
cout << "Y\n";
}
else cout << "N\n";
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/icode-girl/p/4679749.html