poj2402

简单题

View Code
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
using namespace std;

int n;

int main()
{
//freopen("t.txt", "r", stdin);
while (scanf("%d", &n), n)
{
long long x = 0;
while (x * 2 < n)
x = x * 10 + 9;
if (n > x + x / 10)
{
n -= x;
printf("%d", n);
while (n > 0)
{
printf("%d", n % 10);
n /= 10;
}
}
else
{
n -= x / 10;
printf("%d", n);
n /= 10;
while (n > 0)
{
printf("%d", n % 10);
n /= 10;
}
}
putchar('\n');
}
return 0;
}

posted @ 2011-10-02 12:12  金海峰  阅读(177)  评论(0编辑  收藏  举报