HDU 4608 I-number 2013 Multi-University Training Contest 1

定义一个数 y 为 x 的 I-number。对于 y 有如下要求:

1、y > x;

2、y 的每一位之和要为10的倍数(例如 28 每一位之和为 10 ,为 10 的 1 倍);

3、这样的 y 有很多个,但是I-number为最小的那个

注意:x 的长度不会超过 105

这道题目可以直接爆搞,因为可以证明符合要求的 y 一定满足 y < x + 20

但是在敲这道题目的时候需要注意,他会有恶心的前导 0 , 而且不能删除这些前导 0 。 例如,202 对应的   I-number为208。 但如果他输入的是 000202 , 那么输出是 000208 这样。

这道题目除了上面那个坑意外,可以随便搞定,其他的就不赘述了。

附上AC代码:

   1: #include <stdio.h>
   2: #include <math.h>
   3: #include <cstdarg>
   4: #include <string.h>
   5: #include <iostream>
   6: #define LL long long
   7: #define M(a) memset(a, 0, sizeof(a))
   8: using namespace std;
   9:  
  10: void Clean(int count, ...)
  11: {
  12:     va_list arg_ptr;
  13:     va_start (arg_ptr, count);
  14:     for (int i = 0; i < count; i++)
  15:         M(va_arg(arg_ptr, int*));
  16:     va_end(arg_ptr);
  17: }
  18:  
  19: char buf[100009];
  20:  
  21: int deal(int len)
  22: {
  23:     for (int i = 1; i <= len; i++)
  24:         buf[i] -= '0';
  25:     int mark = 0;
  26:     while (1)
  27:     {
  28:         buf[len] += 1;
  29:         for (int i =  len; i >= 0; i--)
  30:         {
  31:             if (buf[i] >= 10)
  32:             {
  33:                 buf[i] -= 10;
  34:                 buf[i - 1] += 1;
  35:             }
  36:         }
  37:         
  38:         if (buf[0]) mark = 1;
  39:         int temp = 0;
  40:         for (int i = 1 - mark; i <= len; i++)
  41:             temp += buf[i];
  42:         if (temp % 10 == 0) return mark;
  43:     }
  44: }
  45:  
  46: int main()
  47: {
  48:     int T, x;
  49:     scanf("%d", &T);
  50:     while (T--)
  51:     {
  52:         Clean(1, buf);
  53:         scanf("%s", &buf[1]);
  54:         int len = strlen((char *)(buf + 1));
  55:         for (int i = 1 - deal(len); i <= len; i++)
  56:             printf("%c", buf[i] + '0');
  57:         puts("");
  58:     }
  59:     return 0;
  60: }
posted @ 2013-07-28 10:55  ~無痕~  阅读(318)  评论(0编辑  收藏  举报