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 <cstdlib>
#include<iomanip>
#include <iostream>

using namespace std;
void f(char optr,int a,int b)
{
     switch(optr)
     {
         case '+':cout<<a+b<<endl;break;
         case '-':cout<<a-b<<endl;break;
         case '*':cout<<a*b<<endl;break;
         case '/':if(a%b==0) cout<<a/b<<endl;//能整除
                  else cout<<fixed<<setprecision(2)<<1.0*a/b<<endl;//不能整除
                 break;
     }
}
int main(int argc, char *argv[])
{
    char optr;
    int a,b,n;
    cin>>n;
    while(n--)
    {
        cin>>optr>>a>>b;
        f(optr,a,b);
    }
    
    system("PAUSE");
    return EXIT_SUCCESS;
}

杭电1170 Balloon Comes的更多相关文章

  1. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  2. 杭电acm阶段之理工大版

    想參加全国软件设计大赛C/C++语言组的同学,假设前一篇<C和指针课后练习题总结>没看完的,请先看完而且依照上面的训练做完,然后做以下的训练. 传送门:http://blog.csdn.n ...

  3. 杭电ACM题单

    杭电acm题目分类版本1 1002 简单的大数 1003 DP经典问题,最大连续子段和 1004 简单题 1005 找规律(循环点) 1006 感觉有点BT的题,我到现在还没过 1007 经典问题,最 ...

  4. 杭电acm习题分类

    专注于C语言编程 C Programming Practice Problems (Programming Challenges) 杭电ACM题目分类 基础题:1000.1001.1004.1005. ...

  5. acm入门 杭电1001题 有关溢出的考虑

    最近在尝试做acm试题,刚刚是1001题就把我困住了,这是题目: Problem Description In this problem, your task is to calculate SUM( ...

  6. 杭电acm 1002 大数模板(一)

    从杭电第一题开始A,发现做到1002就不会了,经过几天时间终于A出来了,顺便整理了一下关于大数的东西 其实这是刘汝佳老师在<算法竞赛 经典入门 第二版> 中所讲的模板,代码原封不动写上的, ...

  7. 杭电OJ——1198 Farm Irrigation (并查集)

    畅通工程 Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇.省政府"畅通工程"的目标是使全省任何两个城镇间都可 ...

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

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

  9. C#利用POST实现杭电oj的AC自动机器人,AC率高达50%~~

    暑假集训虽然很快乐,偶尔也会比较枯燥,,这个时候就需要自娱自乐... 然后看hdu的排行榜发现,除了一些是虚拟测评机的账号以外,有几个都是AC自动机器人 然后发现有一位作者是用网页填表然后按钮模拟,, ...

随机推荐

  1. chart crash

    * thread #155: tid = 0x1fcc10, 0x0000000107626745 gpxj`static gpxj.ChartUtils.decimals (gpxj.ChartUt ...

  2. 示sudo: cd: command not found

    执行sudo cd 时出现 sudo: cd: command not found 原因shell shell是一个命令解析器 所谓shell是一个交互式的应用程序. shell执行外部命令的 时候, ...

  3. Redis分布式

    昨天公司技术大牛做了一个Redis分布式的技术分享: Redis分布式资源: http://redis.io/topics/cluster-tutorialhttp://redis.io/topics ...

  4. PostgreSQL Replication之第十章 配置Slony(4)

    10.4 部署DDLs 对于生产性的应用程序来说,仅仅复制一个表明显是不够的.此外,通过没有办法保证数据从来不会发生改变.在某些时候,部署变化的数据结构(所谓的DDLs)是必要的. 现在的问题是,Sl ...

  5. configuring tortoise git and vs code.

    Preparation, SSH keygen: $ git config --global user.name "calos" $ git config --global use ...

  6. sliverlight 4 vs2010 的安装过程

    今天小白正式开始学习sliverlight 的内容,但是在软件安装的过程中就遇到了问题,查了一下,需要安装对应版本的sdk跟tools,因为在新建项目的时候,可以选择sliverlght,因此,我断定 ...

  7. ASP.NET状态管理策略

    如果要想把信息存储在客户端那可以选择视图状态.控件状态.隐藏字段.cookie.和查询字符串. 1.web窗体页提供viewstate属性作为内置结构,在同一页的多个请求间自动保留值.他作为页面的隐藏 ...

  8. 11---Net基础加强

    替换邮箱用户名部分: using System; using System.Collections.Generic; using System.Linq; using System.Text; usi ...

  9. Oracle数据类型总结

    一 字符串类型 1.1:CHAR类型 CHAR(size [BYTE | CHAR]) CHAR类型,定长字符串,会用空格填充来达到其最大长度.非NULL的CHAR(12)总是包含12字节信息.CHA ...

  10. 夺命雷公狗—angularjs—8—ng-class的简单用法

    我们在正常的业务处理中往往会遇到一些逻辑类的问题,比如各行换色,现在angularjs里面也给我们提供了一个小小的的class处理的方式,废话不多说,如下所示: <!doctype html&g ...