2016 Pacific Northwest Region Programming Contest—Division 2 Problem R — limit 1 second Equality

来源:互联网 发布:周扬青 淘宝 编辑:程序博客网 时间:2024/06/05 16:48

Problem R — limit 1 second Equality
You are grading an arithmetic quiz. The quiz asks a student for the sum of the numbers. Determine if the student taking the quiz got the question correct.
Input
The first and the only line of input contains a string of the form:
a + b = c
It is guaranteed that a, b, and c are single-digit positive integers. The input line will have exactly 9 characters, formatted exactly as shown, with a single space separating each number and arithmetic operator.
Output
Print, on a single line, YES if the sum is correct; otherwise, print NO.
Sample Input Sample Output
1 + 2 = 3 YES
Sample Input Sample Output
2 + 2 = 5 NO
2016 Pacific Northwest Region Programming Contest—Division 2











#include<stdio.h>
#include<stdlib.h>
#include<iostream>
using namespace std;
int main()
{
 char s[10]; 
 gets(s);
 int a = atoi(&s[0]);
 int b = atoi(&s[4]);
 int c = atoi(&s[8]);
 if(a + b == c)
  printf("YES\n");
 else
  printf("NO\n");
 //printf("%c %c %c",s[0],s[4],s[8]);
 return 0;
}
阅读全文
0 0
原创粉丝点击