Printing Tokens | Hackerrank - Samsus Salehin Sabbir

Header Ads

Printing Tokens | Hackerrank

Problem Link : Printing Tokens

Solution :
      Develop by
 Samsus Salehin Sabbir 




  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4. #include <stdlib.h>

  5. int main() {

  6.     char *s;
  7. // Important approach to be remembered
  8.     s = malloc(1024 * sizeof(char));
  9.     scanf("%[^\n]", s);
  10.     s = realloc(s, strlen(s) + 1);
  11.     
  12. //logic
  13.     for(int i = 0; i < strlen(s) ; i++)
  14.     {
  15.         if(s[i] == ' ')
  16.             printf("\n");
  17.         else
  18.             printf("%c",s[i]);
  19.     }    
  20.    
  21.     return 0;
  22. }

No comments

Powered by Blogger.