Tips:一定要确认题设的输出案例里,每行最终有没有空格。
此题ans[i][9]输出后不加空格直接换行,才能Accepted,否则是Presentation Error。
题设可以访问https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=830&problem=3666&mosmsg=Submission+received+with+ID+21673931
#include<iostream>
#include <cstdio>
//#include<time.h>
using namespace std;
const int maxn = 10000;
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
int num = 0;
int T = 0; //turn or times of doing
int ans[maxn + 5][10]= {0}; //maxn+1是至少的
for(int i = 1; i <= maxn; i++) //ans数组必须大于maxn+1,否则i访问越界
{
for(int digit = 1; digit <= i; digit++)
{
int mid = digit;
while(mid)
{
ans[i][mid % 10]++;
mid /= 10;
}
}
}
cin >> T;
while(T--)
{
cin >> num;
for(int i = 0; i <= 8; i++)
{
cout << ans[num][i] << " ";
}
cout << ans[num][9];
cout << endl;
}
//printf("Time used = %.2f", (double)clock() / CLOCKS_PER_SEC);
return 0;
}
数数字Digit Counting: UVa 1225, ACM/ICPC Danang 2007
最新推荐文章于 2021-03-18 22:35:39 发布