Submission #20326671


Source Code Expand

#include<bits/stdc++.h>
using namespace std;

int main()
{
        string n;
        int k;
        cin>> n>>k;
  string s = n;
  
  for(int i =0;i<k;i++)
  {
    int t = s.size();
    
  string h,l;
    
    int arr[t];
    for(int m = 0;m<t;m++)
    {
    arr[m] =0;
    }
    for(int j = 0;j<t;j++){
    int num = s[j] -'0';
      arr[j] =num;
    }
    sort(arr,arr+t);
    
    for(int j = 0;j<t;j++){
      l += to_string(arr[j]);
    }
    reverse(arr,arr+t);
    for(int j = 0;j<t;j++){
      h += to_string(arr[j]);
    }
    int y,z;
    y = atoi(h.c_str());
    z = atoi(l.c_str());
    y-=z;
    s = to_string(y);
  }
  cout << s << endl;
}

Submission Info

Submission Time
Task C - Kaprekar Number
User Rey564219
Language C++ (GCC 9.2.1)
Score 300
Code Size 695 Byte
Status AC
Exec Time 156 ms
Memory 3700 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 31
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
random_01.txt AC 152 ms 3628 KiB
random_02.txt AC 2 ms 3656 KiB
random_03.txt AC 103 ms 3692 KiB
random_04.txt AC 2 ms 3568 KiB
random_05.txt AC 156 ms 3608 KiB
random_06.txt AC 4 ms 3616 KiB
random_07.txt AC 121 ms 3640 KiB
random_08.txt AC 3 ms 3560 KiB
random_09.txt AC 149 ms 3692 KiB
random_10.txt AC 2 ms 3564 KiB
random_11.txt AC 112 ms 3608 KiB
random_12.txt AC 2 ms 3588 KiB
random_13.txt AC 155 ms 3604 KiB
random_14.txt AC 2 ms 3560 KiB
random_15.txt AC 125 ms 3640 KiB
random_16.txt AC 2 ms 3492 KiB
random_17.txt AC 156 ms 3660 KiB
random_18.txt AC 2 ms 3596 KiB
random_19.txt AC 134 ms 3568 KiB
random_20.txt AC 3 ms 3688 KiB
random_21.txt AC 63 ms 3692 KiB
random_22.txt AC 54 ms 3660 KiB
random_23.txt AC 86 ms 3628 KiB
random_24.txt AC 71 ms 3692 KiB
random_25.txt AC 77 ms 3664 KiB
random_26.txt AC 114 ms 3588 KiB
random_27.txt AC 91 ms 3680 KiB
random_28.txt AC 98 ms 3692 KiB
sample_01.txt AC 2 ms 3560 KiB
sample_02.txt AC 3 ms 3700 KiB
sample_03.txt AC 80 ms 3660 KiB