Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /************************************/
- /** 20140923 Exam 01 **/
- /** Maker : Yan **/
- /** E-Mail : [email protected] **/
- /** Date : 2014/09/23 am.11:10 **/
- /************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <string.h>
- int main(int argc, char const *argv[])
- {
- //設定迴圈輸入次數
- int count = 0;
- scanf("%d", &count);
- for(int c = 0; c < count; c++)
- {
- //輸入車牌號碼[固定格式AAA-0000]
- char input_plate_number[8] = {EOF};
- scanf("%s", input_plate_number);
- //用來作為暫存車牌字母所代表的數字
- int num[3] = {0};
- for(int i = 0; i < strlen(input_plate_number); i++)
- {
- //英文字母部分
- if(i < 3)
- {
- //以ASCII 做計算
- str_num[i] = (int)input_plate_number[i] - 65;
- }
- //數字部分
- else if(i > 3)
- {
- //建立暫存數字檔案
- char temp[3] = {EOF};
- for(int j = 0; j < 4; j++)
- {
- temp[j] = input_plate_number[j + 4];
- }
- //直接以atoi 將字串轉換為數字
- num[3] = atoi(temp);
- //跳出迴圈
- break;
- }
- }
- //以if 建立輸出規則(abs 為取絕對值)
- if(abs((num[0] * 26 * 26 + num[1] * 26 + num[2] * 1) - num[3]) <= 100)
- {
- printf("%s : nice.\n", input_plate_number);
- }
- else
- {
- printf("%s : No nice.\n", input_plate_number);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment