| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 531 人关注过本帖
标题:杭电水题......
只看楼主 加入收藏
巴克
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:93
专家分:199
注 册:2012-2-8
结帖率:100%
收藏
已结贴  问题点数:15 回复次数:4 
杭电水题......
上题:

Balloon Comes!

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1611 Accepted Submission(s): 533

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
搜索更多相关主题的帖子: only beautiful addition balloon 
2012-02-22 16:41
巴克
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:93
专家分:199
注 册:2012-2-8
收藏
得分:0 
贴代码:
程序代码:
#include<stdio.h>
int main()
{
    char ch;
    int a,b;
    int i,n;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%c%d%d",&ch,&a,&b);
        switch(ch)
        {
            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==0)
            {printf("%d\n",a/b);break;}
                else
            {
                    printf("%.2f\n",(float)a/b);
                    break;
            }
        }
    }

    return 0;
}
2012-02-22 16:41
巴克
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:93
专家分:199
注 册:2012-2-8
收藏
得分:0 
问题来了:我输入
4
+ 1 2
- 2 1
然后程序就结束了,为什么????
2012-02-22 16:42
laznrbfe
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
帖 子:482
专家分:1599
注 册:2011-5-22
收藏
得分:15 
程序代码:
#include<stdio.h>
int main()
{
    char ch;
    int a=0,b=0;
    int i,n;
    scanf("%d",&n);

    for(i=1;i<=n;i++)
    {
        fflush(stdin);//清除缓冲区
        scanf("%c%d%d",&ch,&a,&b);
        switch(ch)
        {
        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==0)
            {printf("%d\n",a/b);break;}
            else
            {
                printf("%.2f\n",(float)a/b);
                break;
            }
        }
    }
    return 0;
}
2012-02-22 16:57
巴克
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:93
专家分:199
注 册:2012-2-8
收藏
得分:0 
2012-02-22 17:03
快速回复:杭电水题......
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.035875 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved