22-10- HACKERRANK C PROGRAMMING - PRINTING TOKENS
SOLUTION-
MY SOLUTION
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
int i;
char *s;
s = malloc(1024 * sizeof(char));
scanf("%[^\n]", s);
s = realloc(s, strlen(s) + 1);
for(i = 0; s[i] !='\0'; i++){
if(s[i] == ' '){
printf("\n");
}
else {
printf("%c", s[i]);
}
}
return 0;
}
PROBLEM SETTERS SOLUTION
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char *s;
s = malloc(1024 * sizeof(char));
scanf("%[^\n]", s);
s = realloc(s, strlen(s) + 1);
int len = strlen(s);
for(int i = 0; i < len; i++) {
if(s[i] == ' ') {
printf("\n");
}
else {
printf("%c", s[i]);
}
}
free(s);
return 0;
}
No comments:
Post a Comment