Holey_yan

20140923_KUAS_VisualC++_Exam01

Sep 22nd, 2014
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. /************************************/
  2. /** 20140923 Exam 01               **/
  3. /** Maker  : Yan                   **/
  4. /** E-Mail : [email protected] **/
  5. /** Date   : 2014/09/23 am.11:10   **/
  6. /************************************/
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <math.h>
  11. #include <string.h>
  12.  
  13. int main(int argc, char const *argv[])
  14. {
  15.     //設定迴圈輸入次數
  16.     int count = 0;
  17.     scanf("%d", &count);
  18.     for(int c = 0; c < count; c++)
  19.     {
  20.         //輸入車牌號碼[固定格式AAA-0000]
  21.         char input_plate_number[8] = {EOF};
  22.         scanf("%s", input_plate_number);
  23.         //用來作為暫存車牌字母所代表的數字
  24.         int num[3] = {0};
  25.         for(int i = 0; i < strlen(input_plate_number); i++)
  26.         {
  27.             //英文字母部分
  28.             if(i < 3)
  29.             {
  30.                 //以ASCII 做計算
  31.                 str_num[i] = (int)input_plate_number[i] - 65;
  32.             }
  33.             //數字部分
  34.             else if(i > 3)
  35.             {
  36.                 //建立暫存數字檔案
  37.                 char temp[3] = {EOF};
  38.                 for(int j = 0; j < 4; j++)
  39.                 {
  40.                     temp[j] = input_plate_number[j + 4];
  41.                 }
  42.                 //直接以atoi 將字串轉換為數字
  43.                 num[3] = atoi(temp);
  44.                 //跳出迴圈
  45.                 break;
  46.             }
  47.         }
  48.         //以if 建立輸出規則(abs 為取絕對值)
  49.         if(abs((num[0] * 26 * 26 + num[1] * 26 + num[2] * 1) - num[3]) <= 100)
  50.         {
  51.             printf("%s : nice.\n", input_plate_number);
  52.         }
  53.         else
  54.         {
  55.             printf("%s : No nice.\n", input_plate_number);
  56.         }
  57.     }
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment