Reverse Word Wise
Reverse Word Wise
Send Feedback
Reverse Word Wise
String in a single line
Word wise reversed string in a single line
0 <= |S| <= 10^7
where |S| represents the length of string, S.
Welcome to Coding Ninjas
Ninjas Coding to Welcome
Always indent your code
code your indent Always
#include<bits/stdc++.h>
void reverseStringWordWise(char input[]) { // Write your code here int len,i,j,count; len=strlen(input); i=0; while(i<len){ swap(input[i],input[len-1]); i++; len--; } len=strlen(input); count=0; for(i=0;i<=len;i++){ if(input[i]==' ' || input[i]!='\0'){ j=i-1; while(count<j){ swap(input[count],input[j]); j--,count++; } count=i+1; } } }
#include <iostream>#include<bits/stdc++.h>
using namespace std;
void reverseStringWordWise(char input[]) { // Write your code here int len,i,j,count; len=strlen(input); i=0; while(i<len){ swap(input[i],input[len-1]); i++; len--; } len=strlen(input); count=0; for(i=0;i<=len;i++){ if(input[i]==' ' || input[i]!='\0'){ j=i-1; while(count<j){ swap(input[count],input[j]); j--,count++; } count=i+1; } } }
int main() { char input[1000]; cin.getline(input, 1000); reverseStringWordWise(input); cout << input << endl;}
Comments
Post a Comment