HDU 1170

来源:互联网 发布:淘宝网开店费用 编辑:程序博客网 时间:2024/06/15 08:18

Balloon Comes!

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!

题意:输入符号和数字,计算结果。注意数字类型。

#include<stdio.h>int main(){    int a,b,c,i,n;    double d;    char e;    while(scanf("%d",&n)!=EOF)    {        getchar();        for(i=1; i<=n; i++)        {            d=0;            scanf("%c %d %d",&e,&a,&b);            getchar();            switch(e)            {            case '+':                printf("%d\n",a+b);                break;            case '-':                printf("%d\n",a-b);                break;            case '*':                printf("%d\n",a*b);                break;            case '/':            {                if(a/b*b!=a)                    printf("%.2lf\n",(double)a/b);                else                    printf("%d\n",a/b);            }            break;            }        }    }}


1 0
原创粉丝点击