您的位置:首页 > 其它

UVa1583——Digit Generator

2015-09-20 15:08 260 查看
水题。

AC的代码:

#include <iostream>
#include <cstring>
using namespace std;

const int MAX = 105005;
int ans[MAX];

int main()
{
int t, n, i;
memset(ans, 0, sizeof(ans));
for(i = 1; i < MAX; i++)
{
int x = i, y = i;
while(x)
{
y += x % 10;
x /= 10;
}
if(ans[y] == 0 || i < ans[y])
ans[y] = i;
}
while(cin >> t)
{
while(t--)
{
cin >> n;
cout << ans
<< endl;
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: