HDU 1170 Balloon Comes!

 

题意很简单,要注意的是,使用了scanf(“%c”,&op)之后,需要用一个getchar()来读取最后输入的换行符,而平常输入%d的时候则不需要。

#include <stdio.h>
#include <math.h>
#include <iostream>

using namespace std;

void main()
{
	int num=0;

	scanf("%d",&num);
	getchar();
	int i=0;
	while(i < num)
	{
		int a,b;
		char op;
		scanf("%c %d %d",&op,&a,&b);
		getchar();
		if(op == '+')
			printf("%d\n",a+b);
		else if(op == '-')
			printf("%d\n",a-b);
		else if(op == '*')
			printf("%d\n",a*b);
		else if(op == '/')
		{
			if(a%b == 0)
				printf("%d\n",a/b);
			else
				printf("%.2f\n",(float)a/b);
		}
		i++;
	}
}

 

相关文章: