Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <algorithm>
- #include <string.h>
- #include <ctype.h>
- using namespace std;
- char isa[10];
- char martin[10];
- int c;
- char probChar[]={'A','C','M','I','P'};
- long long newP[] = {21*21*21*21*10*10LL,
- 21*21*21*10*10LL,
- 21*21*10*10LL,
- 21*10*10LL,
- 10*10LL,
- 10LL,
- 1LL};
- long long oldP[] = {26*26*10*10*10*10LL,
- 26*10*10*10*10LL,
- 10*10*10*10LL,
- 10*10*10LL,
- 10*10LL,
- 10LL,
- 1LL};
- long long letUntil[30];
- bool goodChar(char a) {
- if (a<'A' || a>'Z')
- return false;
- for (int i=0; i<5; i++)
- if (a==probChar[i])
- return false;
- return true;
- }
- bool valid(char* plate) {
- if (isalpha(plate[4])) {
- for (int i=0; i<5; i++)
- if (!goodChar(plate[i]))
- return false;
- for (int i=5; i<7; i++)
- if (!isdigit(plate[i]))
- return false;
- }
- else {
- for (int i=0; i<3; i++)
- if (plate[i]<'A' || plate[i]>'Z')
- return false;
- for (int i=3; i<7; i++)
- if (!isdigit(plate[i]))
- return false;
- }
- return true;
- }
- long long plateNum(const char* plate) {
- long long num=0;
- if (isalpha(plate[4])) {
- num+=plateNum("ZZZ9999")+1;
- for (int i=0; i<5; i++)
- num+=(letUntil[plate[i]-'A']*newP[i]);
- for (int i=5; i<7; i++)
- num+=((plate[i]-'0')*newP[i]);
- }
- else {
- for (int i=0; i<3; i++)
- num+=((plate[i]-'A')*oldP[i]);
- for (int i=3; i<7; i++)
- num+=((plate[i]-'0')*oldP[i]);
- }
- return num;
- }
- int main() {
- long long sum=0;
- for (char i='A'; i<='Z'; i++)
- if (goodChar(i)) letUntil[i-'A']=sum++;
- while (1) {
- scanf(" %s %s %d", martin, isa,&c);
- if (!strcmp(martin,"*") && !strcmp(isa,"*") && !c)
- break;
- if (!valid(isa)) {
- printf("N\n");
- continue;
- }
- long long nIsa = plateNum(isa);
- long long nMartin = plateNum(martin);
- if (nIsa-nMartin>0 && nIsa-nMartin<=c)
- printf("Y\n");
- else printf("N\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement