好车牌(模拟)

Description

烟台最近使用一种新的车牌号码: ABC-0123(3个字母+4个数字)

如果字母部分和数字部分差值的绝对值最多为100则认为是好车牌。

字母部分的值的以26进制(A……Z表示)计算。比如第一部分为"ABC",它的值为28(0*26^2 + 1*26^1 + 2*26^0)。因为 |28-123|<=100,所以"ABC-0123"为好车牌。

给出一系列的车牌,你编个程序计算一下哪些是好车牌,哪些不是。

Input

第一行为整数N(1<=N<=100),表示车牌的个数。

接下来是N行,每行一个格式为LLL-DDDD的车牌。

Output

对每个车牌输出 "nice" or "not nice" (不包含引号)

Sample Input

2
ABC-0123
AAA-9999

Sample Output

nice
not nice


 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<math.h>
 4 #include<stdlib.h>
 5 int main()
 6 {
 7     int t,s1,s2,ans,i,sum;
 8     char s[10];
 9     scanf("%d",&t);
10     getchar();
11     while(t--)
12     {
13         gets(s);
14         s2=0;
15         s1=0;
16         for(i=0;i<=2;i++)
17         {
18             s1=s1*26+(s[i]-65);
19         }
20         for(i=4;i<=7;i++)
21         {
22             s2=s2*10+s[i]-48;
23         }
24         sum=abs(s1-s2);
25         if(sum<=100)
26             printf("nice
");
27         else
28             printf("not nice
");
29     }
30     return 0;
31 }
原文地址:https://www.cnblogs.com/wkfvawl/p/9064733.html