HDU 1170 Balloon Comes!(水~)

Description
给出运算符(加减乘除)以及两个整数,输出这两个整数的运算结果
Input
第一行为用例组数T,每组用例占一行包括一个运算符和两个整数a和b表示被运算数
Output
输出运算结果,注意除法运算时如果结果是整数则输出整数,如果是浮点数则小数点后保留两位
Sample Input
4
+ 1 2
- 1 2
* 1 2
/ 1 2
Sample Output
3
-1
2
0.50
Solution
简单题
Code

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

}

你可能感兴趣的:(HDU 1170 Balloon Comes!(水~))