Submission #20319921


Source Code Expand

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define INF 2147483647
#define ft first
#define sec second
#define pr pair<int,int>
#define ISCC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
ll t ,n ,k;
string s ,pre;
inline ll next(string tp)
{
	ll num=0 ,len = tp.size() ,ten = pow(10 ,len-1);
	for(int i=0 ;i<len ;i++)
	{
		num += (s[i]-'0')*ten;
		ten/=10;
	} 
	return num;
}
int main() 
{
	cin>>s>>k;
	pre = s;
	ll a=next(s) ,b=0;
	while(k--)
	{
		stringstream ss;
		sort(s.begin() ,s.end() ,greater<>());
		a = next(s);
		sort(s.begin() ,s.end());
		b = next(s);
		a -= b;
		if(a==0) break;
		ss << a;
		ss >> s;
	}
	cout << a << ' ';
}

Submission Info

Submission Time
Task C - Kaprekar Number
User ck1080012
Language C++ (GCC 9.2.1)
Score 300
Code Size 723 Byte
Status AC
Exec Time 84 ms
Memory 4044 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 79 ms 3904 KiB
random_02.txt AC 2 ms 3908 KiB
random_03.txt AC 54 ms 3908 KiB
random_04.txt AC 2 ms 3848 KiB
random_05.txt AC 81 ms 3872 KiB
random_06.txt AC 2 ms 3944 KiB
random_07.txt AC 61 ms 3820 KiB
random_08.txt AC 2 ms 3972 KiB
random_09.txt AC 83 ms 3944 KiB
random_10.txt AC 2 ms 3904 KiB
random_11.txt AC 59 ms 3972 KiB
random_12.txt AC 3 ms 3852 KiB
random_13.txt AC 75 ms 3940 KiB
random_14.txt AC 2 ms 3908 KiB
random_15.txt AC 66 ms 3916 KiB
random_16.txt AC 2 ms 3860 KiB
random_17.txt AC 84 ms 3940 KiB
random_18.txt AC 2 ms 3832 KiB
random_19.txt AC 76 ms 3912 KiB
random_20.txt AC 2 ms 3908 KiB
random_21.txt AC 50 ms 3788 KiB
random_22.txt AC 50 ms 4044 KiB
random_23.txt AC 61 ms 3908 KiB
random_24.txt AC 48 ms 4000 KiB
random_25.txt AC 48 ms 4012 KiB
random_26.txt AC 66 ms 3860 KiB
random_27.txt AC 48 ms 3872 KiB
random_28.txt AC 53 ms 3820 KiB
sample_01.txt AC 3 ms 3612 KiB
sample_02.txt AC 2 ms 3824 KiB
sample_03.txt AC 75 ms 3912 KiB