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;
}

你可能感兴趣的:(poj)