Advertisement
royalsflush

CPCARROS SPOJ Br AC

Sep 24th, 2012
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <algorithm>
  3. #include <string.h>
  4. #include <ctype.h>
  5. using namespace std;
  6.  
  7. char isa[10];
  8. char martin[10];
  9. int c;
  10. char probChar[]={'A','C','M','I','P'};
  11. long long newP[] = {21*21*21*21*10*10LL,
  12.         21*21*21*10*10LL,
  13.         21*21*10*10LL,
  14.         21*10*10LL,
  15.         10*10LL,
  16.         10LL,
  17.         1LL};
  18. long long oldP[] = {26*26*10*10*10*10LL,
  19.         26*10*10*10*10LL,
  20.         10*10*10*10LL,
  21.         10*10*10LL,
  22.         10*10LL,
  23.         10LL,
  24.         1LL};
  25. long long letUntil[30];
  26.  
  27. bool goodChar(char a) {
  28.     if (a<'A' || a>'Z')
  29.         return false;
  30.     for (int i=0; i<5; i++)
  31.         if (a==probChar[i])
  32.             return false;
  33.     return true;
  34. }
  35.  
  36. bool valid(char* plate) {
  37.     if (isalpha(plate[4])) {
  38.         for (int i=0; i<5; i++)
  39.             if (!goodChar(plate[i]))
  40.                 return false;
  41.        
  42.         for (int i=5; i<7; i++)
  43.             if (!isdigit(plate[i]))
  44.                 return false;
  45.     }
  46.     else {
  47.         for (int i=0; i<3; i++)
  48.             if (plate[i]<'A' || plate[i]>'Z')
  49.                 return false;
  50.        
  51.         for (int i=3; i<7; i++)
  52.             if (!isdigit(plate[i]))
  53.                 return false;
  54.     }
  55.  
  56.     return true;
  57. }
  58.  
  59. long long plateNum(const char* plate) {
  60.     long long num=0;
  61.    
  62.     if (isalpha(plate[4])) {
  63.         num+=plateNum("ZZZ9999")+1;
  64.        
  65.         for (int i=0; i<5; i++)
  66.             num+=(letUntil[plate[i]-'A']*newP[i]);
  67.         for (int i=5; i<7; i++)
  68.             num+=((plate[i]-'0')*newP[i]);
  69.     }
  70.     else {
  71.         for (int i=0; i<3; i++)
  72.             num+=((plate[i]-'A')*oldP[i]);
  73.         for (int i=3; i<7; i++)
  74.             num+=((plate[i]-'0')*oldP[i]);
  75.     }
  76.    
  77.     return num;
  78. }
  79.  
  80. int main() {
  81.     long long sum=0;
  82.     for (char i='A'; i<='Z'; i++)
  83.         if (goodChar(i)) letUntil[i-'A']=sum++;
  84.  
  85.     while (1) {
  86.         scanf(" %s %s %d", martin, isa,&c);
  87.         if (!strcmp(martin,"*") && !strcmp(isa,"*") && !c)
  88.             break;
  89.  
  90.         if (!valid(isa)) {
  91.             printf("N\n");
  92.             continue;
  93.         }
  94.  
  95.         long long nIsa = plateNum(isa);
  96.         long long nMartin = plateNum(martin);
  97.  
  98.         if (nIsa-nMartin>0 && nIsa-nMartin<=c)
  99.             printf("Y\n");
  100.         else printf("N\n");
  101.     }
  102.  
  103.     return 0;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement