TAImatem

maxnumsum

Mar 12th, 2017
128
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include "stdio.h"
  3.  
  4. #define INF 99999999
  5. #define E 0.00000001
  6.  
  7. int main()
  8. {
  9.     int n[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, f, l;
  10.     long long in, c;
  11.     scanf("%I64d", &in);
  12.     c = in;
  13.     while (c > 9)
  14.     {
  15.         n[c % 10]++;
  16.         c /= 10;
  17.     }
  18.     f = c;
  19.     l = n[0] + n[1] + n[2] + n[3] + n[4] + n[5] + n[6] + n[7];
  20.     if (l || (n[8] > 1))
  21.     {
  22.         f--;
  23.         n[9] += n[8] + l;
  24.         l = 1;
  25.         in = f;
  26.         while (n[9])
  27.         {
  28.             in *= 10;
  29.             in += 9;
  30.             --n[9];
  31.         }
  32.     }
  33.     printf("%I64d", in);
  34.     return 0;
  35. }
RAW Paste Data