0
Youtube Link Finder Code Coach https://www.sololearn.com/coach/74?ref=app
#include <iostream> #include <string.h> #include <algorithm> using namespace std; int main() { string a,ans; cin>>a; ans+='\0'; for (int i=a.length();i>=0;i--) { if (a[i] == '=') break; else if (a[i] == '/' && a[i-1] == 'e') break; ans+=a[i]; } reverse(ans.begin(),ans.end()); cout<<ans; return 0; } This is my code, I am getting the output correctly but my test cases are failing. Can someone help ?
1 Réponse
+ 2
you don't need null character just make
ans = "" //before loop.
make loop condition look like :
for (int i=a.length()-1;i>0;i--)
//added -1 and removed =