Codejam Round 1A Append Sort

Hey,
This code was able to clear the 12 Marks test case in Google codejam round 1a for Append sort,
but gets failed in 2nd test case. Please help me, debugging the issue.
Thankk
#include <bits/stdc++.h>
using namespace std;
bool cmp(string &x,string &y)
{
if(x.size()<y.size())
return true;
else if(x.size()==y.size())
{
for(int i=0;i<x.size();i++)
{
if(y[i]>x[i])
{
return true;
}
else if(y[i]==x[i]&&i!=x.size()-1)
continue;
else
return false;

}
}

else
return false;
}
int solve(string &x,string &y)
{

if(x==y)
{
    y.push_back('0');
    return 1;
}

int i=y.size();
int ans=0;

if(x.substr(0,i)==y)
{
ans=x.size()-y.size();

 if(x.back()=='9')
 {
     y=x;
     y.push_back('0');
    ans++;
    return ans;
 }

 else
 {
     y=x;
     y[y.size()-1]=x[x.size()-1]+1;
     
     return ans;
 }

}
while(!cmp(x,y))
{

 y.push_back('0');

ans++;

}

return ans;

}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;

for(int z=1;z<=t;z++)
{
int ans=0;
int n;
cin>>n;
vectorv(n);
for(int i=0;i<n;i++)
cin>>v[i];
for(int i=0;i<n-1;i++)
ans+=solve(v[i],v[i+1]);
cout<<“Case #”<<z<<": "<<ans<<endl;

}
return 0;
}

Format your code.
Use ``` at the start and end of code.

Were you getitng TLE or WA?