實機體驗,再天天抽M8工程師靠存股年領百萬股息正妹的東京自助旅行24天後重啟院會 兩岸...
2012-12-24 08:40:20 人氣(44) | 回應(0) | 推薦(0) | 收藏(0) 上一篇 | 下一篇

[UVA][parse] 11878 - Homework Checker

0
收藏
0
推薦


  Homework Checker 

� Your younger brother has just finished his homework for the part "additions and subtractions for integers not greater than one hundred" and asks you to check the answers. Each question (together with the answer computed by your younger brother) is formatted either as a + b = c or a - b = c, where a and b are numbers prepared by the teacher (they are guaranteed to be non-negative integers not greater than 100), c is the answer computed by your younger brother and is either a non-negative integer not greater than 200, or a single character `?' (that means, he is unable to compute the answer).

Input 

There will be at most 100 lines in the input. Each line contains a question with your younger brother's answer, formatted as stated above. There will be no space characters in each line (excluding the newline character). Numbers will never have leading zeros.

Output 

Print a single integer in a line, the number of correct answers.

Sample Input 

1+2=3
3-1=5
6+7=?
99-0=99

Sample Output 

2



Problemsetter: Rujia Liu, Special Thanks: Yiming Li


#include <stdio.h>

int main() {
    char cmd[50];
    int a, b, c, ans = 0;
    while(gets(cmd)) {
        if(sscanf(cmd, "%d+%d=%d", &a, &b, &c) == 3) {
            if(a+b == c)
                ans++;
        }
        if(sscanf(cmd, "%d-%d=%d", &a, &b, &c) == 3) {
            if(a-b == c)
                ans++;
        }
    }
    printf("%d\n", ans);
    return 0;
}


11878Homework Checkerstring parse
台長:Morris
人氣(44) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][dp] 11032 - Function Overloading
此分類上一篇:[UVA] 1189 - Find The Multiple

我要回應
是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入以下數字 (ex:123)

(有*為必填)
詳全文