Can i try the solution in this way if yes then plz solve it .
#include
using namespace std;
int main() {
string str;
cin>>str;
for(int i=0;i<str.length();i++){
cout<<str[i]<<str[i+1]-str[i];
}
return 0;
}
Can i try the solution in this way if yes then plz solve it .
#include
using namespace std;
int main() {
string str;
cin>>str;
for(int i=0;i<str.length();i++){
cout<<str[i]<<str[i+1]-str[i];
}
return 0;
}
Yes, your approach is correct, you only need a small modification, I have edited the code, try to submit now,
Thanks mam, i got the solution.
//my code
#include<bits/stdc++.h>
using namespace std;
int main()
{
string A;
cin>>A;
int i;
int n=A.length();
for( i=0;i<n-1;i++)
{
cout<<A[i];
cout<<A[i+1]-A[i];
}
cout<<A[i]<<endl;
}
Mam can you please specify the reason for thr edits you have made
ie
out<<str[str.length()-1];
why this line is used
#include
#include
using namespace std;
void StringASCIIdifference(string str) {
//int ascii;
for(int i=0; i<str.length()-1; i++) {
//ascii=str[i+1]-str[i];
cout<<str[i]<<str[i+1]-str[i];
}
cout<<str[str.length()-1];
}
int main() {
string str;
getline(cin, str);
if(str.length()>2 && str.length()<1000)
StringASCIIdifference(str);
return 0;
}
Actually when I submitted this code then some of the cases are failed
Can you give reason why is it happen??