1 Write a program that will replace multiple consecutive occurrences of a character with single occurrence, and print the result in the reverse order.
For example, if the input string is aaaaEEGCCCCCxEEf , the output should be fExCcGEa
The input string of characters should be read from STDIN and the result should be written to STDOUT
Other than the required output, no other characters / string or message should be written to STDOUT.
You can assume that the input string length will not exceed 30 characters
Sample Testcases:
Testcase 1 Input
Testcase 1 Output
aaaaEE GCCCCCCCXEE
fEXCOGES
Answers
Answer:
#include<stdio.h>
int main ()
{
char a [15];
cout <<" Enter a string "<< endl ;
cin >> a ;
cout << a [ 0 ];
for (int i = 1; i < 15; i++)
{
if ( a [i] != a [i-1] )
{
cout << a [i] ;
}
}
return 0;
}
Explanation:
Here the program accepts a string, using the "stdio" header and then checks every character of the word that whether it is same as the previous character, if it is not same then it is printed else it is skipped.
Explanation:
1 Write a program that will replace multiple consecutive occurrences of a character with single occurrence, and print the result in the reverse order.
For example, if the input string is aaaaEEGCCCCCxEEf , the output should be fExCcGEa
The input string of characters should be read from STDIN and the result should be written to STDOUT
Other than the required output, no other characters / string or message should be written to STDOUT.
You can assume that the input string length will not exceed 30 characters
Sample Testcases:
Testcase 1 Input
Testcase 1 Output
aaaaEE GCCCCCCCXEE
fEXCOGES