Can someone please tell me what’s wrong with the following code?
#include
#include <stdio.h>
#include
#include
using namespace std;
signed int st(string a, signed int b) {
vector v;
int asize=int(a.size());
int bsize=int(to_string(b).size());
if(a==to_string(b)) {
return 0;
}
else if((asize>bsize) && (b>0) && asize>1) {
int j=1;
while((j<=bsize) && a.substr(0,j).size()>0) {
v.push_back( st( a.erase(0,j), b-stoi(a.substr(0,j))));
j++;
}
int i=0;
while((v.begin()+i) < v.end()) {
if(v[i]== -1) {
v.erase(v.begin()+i);
}
else {
i++;
}
}
if(v.size()>0) {
return (*min_element(v.begin(), v.end()) +1);
}
else {
return -1;
}
}
else if((asize==bsize) && b>0 && asize>1) {
v.push_back( st( a.erase(0,1), b-stoi(a.substr(0,1))));
int i=0;
while((v.begin()+i) < v.end()) {
if(v[i]== -1) {
v.erase(v.begin()+i);
}
else {
i++;
}
}
if(v.size()>0) {
return (*min_element(v.begin(), v.end()) +1);
}
else {
return -1;
}
}
else {
return -1;
}
}
int main() {
signed int a,b;
string c;
scanf("%d",&a);
cin>>c;
scanf("%d",&b);
signed int final=st(c,b);
cout<<final<<endl;
return 0;
}
(Sorry, the code is not documented :P)