Help a PhD candidate out!解题报告
来源:互联网 发布:数据字典 javaweb 编辑:程序博客网 时间:2024/05/18 01:38
题目摘要:Jon Marius forgot how to add twonumbers while doing research for his PhD. And now he has a long list of additionproblems that he needs to solve, in addition to his computer science ones!Canyou help him?On his current list Jon Marius has two kinds of problems: additionproblems on the form "a+b" and the ever returning problem"P=NP".Jon Marius is a quite distracted person, so he might have so solvethis last problem several times, since he keeps forgetting the solution.Also,he would like to solve these problems by himself, so you should skip these.
题目大意:若是出入a+b,那么输出其值。如果输入P=NP,那么输出skipped。
输入输出要求:
Input
The first line of input will be a singleinteger N
(1<=N<=1000) denoting the number of testcases.
Then follow N lines with either"P=NP" or an addition problem on the form "a + b",
where a, b∈ [0, 1000] are integers.
Output
Output the result of each addition. Forlines containing \P=NP", output \skipped".
输入输出样例:
Sample input
4
2+2
1+2
P=NP
0+0
Sample output
4
3
skipped
0
解题思路:用一个字符数组储存输入的内容,如果第一个字符是P,那么输出skipped。否则的话用sscanf提取数字a,b,然后输出a+b即可。
代码:
#include<stdio.h>
#include<string.h>
char str[20];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
getchar();
while(n--)
{
memset(str,'\0',sizeof(str));
int a,b;
gets(str);
if(str[0]=='P')
printf("skipped\n");
else
{
sscanf(str,"%d+%d",&a,&b);
printf("%d\n",a+b);
}
}
}
return 0;
}
解题感想:巧用sscanf,so easy!
- Help a PhD candidate out!解题报告
- Help Johnny解题报告
- A - SnowflakeSnowSnowflakes解题报告
- A - A+B(解题报告)
- pku 1222 EXTENDED LIGHTS OUT 解题报告
- 解题报告 之 HDU5335 Walk Out
- A+B Coming 解题报告
- USACO A Game解题报告
- 解题报告 codeforces 242A
- USACO A Game 解题报告
- codeforces 1A 解题报告
- A simple problem解题报告
- A - No Brainer解题报告
- E - A + B解题报告
- A - Lake Counting解题报告
- 解题报告:大牛也会不A题
- 大牛也会不A题(解题报告)
- CODEFORCES 534A 解题报告
- CPU时间片
- codility上的问题 (22)Phi 2012
- 转载:PostgreSQL分区表(Table Partitioning)应用
- 青春代码,微电
- Qt安装—搭建VS2008+QT开发环境
- Help a PhD candidate out!解题报告
- 代码调试方法,注意事项(一个菜鸟的感受)
- Codeforces Beta Round #74 (Div. 2) / 90B African Crossword (模拟)
- 盗Q过程分析(待完善,仅用于分析)
- MySQL 获得当前日期时间\时间戳 函数
- 工作流软件如何成为未来web的支柱(转载36氪)
- easyUI 使用验证控件
- 拷贝构造函数的参数为什么必须使用引用类型
- easyui 获取combox数据textField