2292 - 买气球
Time Limit : 1 秒
Memory Limit : 128 MB
每年的ACM新生赛都要买好多好多的气球,小Q今年又被派去买气球了。小Q去买气球的时候,老板只告诉了小Q一共要付多少钱,而小Q只知道需要买多少个气球。请你告诉他每个气球要多少钱.
Input
输入数据有多组,每组占一行。
一个最多保留两位小数的浮点数m和一个整数n。分别代表要付的总钱数和气球数
0<m<10000,0<n<100
Output
每组数据输出一个最多保留两位小数的数。代表每个气球的价格。小数部分不输出末尾的0。若小数部分全为0则输出整数。(注意是四舍五入地保留两位小数)
Examples
Input Format
1 3
Output Format
0.33
Solution C++
#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <time.h> using namespace std; int main() { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); float n, m; while(cin >> n >> m) { double sum = n / m; char str[1000]; sprintf(str,"%.2f",sum); int len = strlen(str); if(str[len - 2] == '0' && str[len - 1] == '0') str[len - 3] = 0; else if(str[len - 1] == '0') str[len - 1] = 0; printf("%s\n",str); } return 0; }