Balloon Comes!
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 16847    Accepted Submission(s): 6150

Problem Description
The contest starts now! How excited it is to see balloons floating around. You, one of the best programmers in HDU, can get a very beautiful balloon if only you have solved the very very very... easy problem.
Give you an operator (+,-,*, / --denoting addition, subtraction, multiplication, division respectively) and two positive integers, your task is to output the result.
Is it very easy?
Come on, guy! PLMM will send you a beautiful Balloon right now!
Good Luck!

Input
Input contains multiple test cases. The first line of the input is a single integer T (0<T<1000) which is the number of test cases. T test cases follow. Each test case contains a char C (+,-,*, /) and two integers A and B(0<A,B<10000).Of course, we all know that A and B are operands and C is an operator.

Output
For each case, print the operation result. The result should be rounded to 2 decimal places If and only if it is not an integer.

Sample Input
4
+ 1 2
- 1 2
* 1 2
/ 1 2

Sample Output
3
-1
2
0.50

#include <stdio.h>
int main()
{int n;
 scanf("%d",&n);
 getchar();
 while(n--)
 {int a,b;
  char c;
  scanf("%c%d%d",&c,&a,&b);
  getchar();
  if(c=='/')
  {if(a/b==(double)a/b)
  printf("%d\n",a/b);
  else
  printf("%.2lf\n",(double)a/b);
  }
  if(c=='+')
  printf("%d\n",a+b);
  if(c=='-')
  printf("%d\n",a-b);
     if(c=='*')
  printf("%d\n",a*b);
 }
 return 0;
}

第一次少用了第二个getchar();而且没有考虑a/b结果为整数应输出整数
注意:要用两次getchar();   当且仅当a/b结果为小数时,结果保留两位小数,结果不为小数时,输出整数

读入字符要注意两点。第一:注意空格,例如输入a b那么要写成scanf("%c %c",&x,&y),这样可以把空格中间的空格读掉,因为空格也是一个字符,如果不这样做的话字符b就读不到;第二,读完字符后要加一个getchar(),因为scanf是不能把回车换行符读取的,故当读入第二组数据的时候读的是上一组数据留下来的换行符这个字符。
 

【ACM】hdu_1170_Balloon Comes!_201307261946的更多相关文章

  1. 高手看了,感觉惨不忍睹——关于“【ACM】杭电ACM题一直WA求高手看看代码”

    按 被中科大软件学院二年级研究生 HCOONa 骂为“误人子弟”之后(见:<中科大的那位,敢更不要脸点么?> ),继续“误人子弟”. 问题: 题目:(感谢 王爱学志 网友对题目给出的翻译) ...

  2. 【ACM】HDU1008 Elevator 新手题前后不同的代码版本

    [前言] 很久没有纯粹的写写小代码,偶然想起要回炉再来,就去HDU随便选了个最基础的题,也不记得曾经AC过:最后吃惊的发现,思路完全不一样了,代码风格啥的也有不小的变化.希望是成长了一点点吧.后面定期 ...

  3. 【ACM】魔方十一题

    0. 前言打了两年的百度之星,都没进决赛.我最大的感受就是还是太弱,总结起来就是:人弱就要多做题,人傻就要多做题.题目还是按照分类做可能效果比较好,因此,就有了做几个系列的计划.这是系列中的第一个,解 ...

  4. 【ACM】那些年,我们挖(WA)过的最短路

    不定时更新博客,该博客仅仅是一篇关于最短路的题集,题目顺序随机. 算法思想什么的,我就随便说(复)说(制)咯: Dijkstra算法:以起始点为中心向外层层扩展,直到扩展到终点为止.有贪心的意思. 大 ...

  5. 【ACM】不要62 (数位DP)

    题目:http://acm.acmcoder.com/showproblem.php?pid=2089 杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer).杭州交通管理局经常会扩充一些的士车牌照,新 ...

  6. 【Acm】八皇后问题

    八皇后问题,是一个古老而著名的问题,是回溯算法的典型例题. 其解决办法和我以前发过的[算法之美—Fire Net:www.cnblogs.com/lcw/p/3159414.html]类似 题目:在8 ...

  7. 【ACM】hud1166 敌兵布阵(线段树)

    经验: cout 特别慢 如果要求速度 全部用 printf !!! 在学习线段树 内容来自:http://www.cnblogs.com/shuaiwhu/archive/2012/04/22/24 ...

  8. 【acm】杀人游戏(hdu2211)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2211 杀人游戏 Time Limit: 3000/1000 MS (Java/Others)    M ...

  9. 【ACM】How many prime numbers

    http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=2&sectionid=1&problemid=2 #inclu ...

随机推荐

  1. 通过命令行升级git for windows

    git update-git-for-windows 配置了正确的代理,就可以通过命令行直接升级.最好是可以访问谷歌的代理,否则国内的网络通过命令行升级,下载到一半,就会失败.

  2. nodejs安装express

    最近在看<Node.js开发指南>,看到使用nodejs进行web开发的时候,准备创建ejs项目遇到问题了, 书上命令为: 1 express -t ejs microblog 可是执行后 ...

  3. Win10切换JDK版本

    开发项目由于使用JDK版本不同,来回配置环境变量有点繁琐,用了一天百度得到的方法 1:安装不同版本的JDK,这个应该都可以完成 2:配置环境变量 CLASSPATH.;%JAVA_HOME%\lib\ ...

  4. Android Studio 将module打成jar包

    1.新建测试工程,工程里面有两个module,app是Android工程,mylibrary是Android Library库. 2.打开mylibrary目录下的build.gradle文件,加入下 ...

  5. AndroidStudio怎样导入library项目库

    先打开一个Project,然后将libraryr的项目作为module进行导入: File菜单->import module菜单 以上只是导入进来,还没有作为与project真正有效的一部分.需 ...

  6. Deutsch lernen (10)

    Dieser Weg Dieser Weg wird kein leichter sein. Dieser Weg wird steinig und schwer. Nicht mit vielen ...

  7. openMSP430之io_test

    openMSP430: IO functionality test with interupt #include "omsp_system.h" volatile char shi ...

  8. dubbo介绍及实战

    1. dubbo是什么? Dubbo是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,以及SOA服务治理方案.其核心部分包含: 远程通讯: 提供对多种基于长连接的NIO框架抽象封 ...

  9. Percona Xtrabackup导出/导入单表

    默认情况下,InnoDB表不能通过直接复制表文件的方式在mysql服务器之间进行移植,即便使用了innodb_file_per_table选项.而使用Xtrabackup工具可以实现此种功能,不过,此 ...

  10. 【技术累积】【点】【Java】【12】几种常见编码(持续更新)

    问题描述 有这么一段代码: String question = new String(record.getQuestion().getBytes("iso-8859-1"), &q ...