#include <iostream>
using namespace std;
int main()
{
int n, a[7] = {100, 50, 20, 10, 5, 2, 1};
cin >> n;
printf("%d\n", n);
for (int i = 0; i < 7; i ++ )
{
printf("%d nota(s) de R$ %.2lf\n", n / a[i], a[i]);
n %= a[i];
}
return 0;
}
时间转化
#include <iostream>
using namespace std;
int main()
{
int t;
cin >> t;
int h = t / 3600;
int m = t % 3600 / 60;
int s = t % 60;
cout << h << ':' << m << ':' << s << endl;
return 0;
}
简单计算
#include<iostream>
using namespace std;
int main()
{
int code,n;
double price,sum=0.0;
for(int i=1;i<=2;i++)
cin>>code>>n>>price,sum+=n*price;
printf("VALOR A PAGAR: R$ %.2lf",sum);
return 0;
}
燃料消耗
这个题数据范围挺大,小心溢出
#include<iostream>
using namespace std;
int a, b;
int main() {
scanf("%d%d", &a, &b);
printf("%.3lf", a * 1.000 / 12 * b); //先除再乘,以免double溢出
return 0;
}
钞票和硬币
数值放大 解法和上面类似
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
double n;
cin >> n;
int m = (int)(n * 100);
double a[12] = {10000, 5000, 2000, 1000, 500, 200, 100, 50, 25, 10, 5, 1};
int ans[12] = {0};
for (int i = 0; i < 12; i++)
{
int cnt = 0;
while (m >= a[i])
{
m -= a[i];
cnt++;
}
ans[i] = cnt;
}
puts("NOTAS:");
for (int i = 0; i < 6; i++)
printf("%d nota(s) de R$ %.2lf\n", ans[i], (double)a[i] / 100);
puts("MOEDAS:");
for (int i = 6; i < 12; i++)
printf("%d moeda(s) de R$ %.2lf\n", ans[i], (double)a[i] / 100);
return 0;
}