24h購物| | PChome| 登入
2012-12-24 08:40:20| 人氣549| 回應0 | 上一篇 | 下一篇

[UVA][parse] 11878 - Homework Checker

推薦 0 收藏 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;
}


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

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文