False Number Codechef Solution

False Number Solution Problem Code: FALSNUM

One day, Chef’s friend gave him a wrong number WW containing N+1N+1 digits and said that the actual number AA is the largest possible number that can be obtained from deleting exactly one digit of WW. Chef was able to find AA but forgot WW.

Given AA, find the smallest possible number WW of length N+1N+1 without leading 00’s that is consistent with the story above. We can show that there is always at least one such WW consistent with the story.

Input

  • The first line contains an integer TT, the number of test cases. Then the test cases follow.
  • Each test case contains a single line of input, an integer AA.

Output

For each testcase, output in a single line string representing the answer to the problem.

Constraints

  • 1≤T≤1001≤T≤100
  • 0≤Ai≤90≤Ai≤9 for all valid ii, where AiAi denotes the ii-th digit of AA
  • A1≠0A1≠0 (no leading zero)
  • 10≤|A|≤500010≤|A|≤5000, where |A||A| denotes the number of digits of AA

Subtasks

Subtask #1 (100 points): Original constraints

Sample Input

2
9876543211
12345678999

Sample Output

19876543211
102345678999

Explanation

It can be proven that the above output strings are the smallest possible numbers from which you can arrive at the correct number in the input.

Program:

#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
using namespace std;




void solve(){

    string s;
    cin>>s;

    if(s[0] != '1'){
      cout<<"1"<<s<<endl;
      return ;
    }
    
    cout<<s[0]<<"0";

    for(int i=1;i<s.size();i++) cout<<s[i];
      cout<<endl;

}

int32_t main(){

  #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
  #endif

    int T;
    cin>>T;
    while(T--){
      solve();
    }

}

Weekly Contest 247

Biweekly Contest 55

June Long Challenge 2021 Solutions

March Long Challenge 2021 Solutions

April Long Challenge 2021 Solutions

Codechef Long Challenge Solutions

February Long Challenge 2021

January Long Challenge 2021

November Challenge 2020 SOLUTION CodeChef

October Lunchtime 2020 CodeChef SOLUTIONS

Related :

Related :

Leave a Comment

Please Click on 1 or 2 Ads to help us run this site.
+