Click here to Skip to main content
15,306,245 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
count=0
r=[]
def func1(c):
global r
global count
if c in r:
return
else:
r.append(c)
c=c+1
c=str(c)
c=c.rstrip('0')
c=int(c)
count=count+1
func1(c)


n=int(input())
count=0
func1(n)
print(count)

What I have tried:

#include <iostream>
#include<bits stdc++.h="">
using namespace std;
//int counter=0;

int cnt=0;
int solve(int n)
{
vector<int>vec;
string res=to_string(n);
for(int i=res.size()-1;i>=0;i--)
{
if(res[i]=='0')
{
res.erase(res.begin()+i);
}
}
int res1=stoi(res);
vec.push_back(res1);
cnt=cnt+1;
//n=n+1;
for(int i=0;i<vec.size();i++)
{
="" if(vec[i]="=n){
" break;
="" return="" cnt;
="" }
=""
="" solve(n+1);
="" res1;
}

int="" main()
{
="" int="" n;
="" cin="">>n;
int res2;
res2=solve(n);
cout<
Posted
Updated 30-Apr-21 5:28am

1 solution

This is not a code conversion service: we are not here to translate code for you.
Even if we did, what you would end up with would not be "good code" in the target language – they are based on very different frameworks, and what makes something work in one language does not always "translate" directly into another.
So what you end up with is very poor code, that is difficult if not impossible to maintain, that can’t be upgraded nicely, and that will cause you immense headaches if the original is changed. And it’ll be a nightmare to debug if it doesn’t work "straight out of the box".
Instead, use the source code as a specification for a new app written in and for the target language / framework and write it from scratch using the original as a "template". You will get a much, much better result that will save you a lot of time in the long run.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900