Advertisement
Guest User

Idõpontok

a guest
Feb 26th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.74 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main()
  6. {
  7.     int hh;
  8.     char mm[10];
  9.     const char str[80];
  10.  
  11.     char *token;
  12.  
  13. while ((fscanf(stdin, "%s", str)) != EOF) {
  14.  
  15.     token = strtok(str, ".");
  16.     hh = atoi(token);
  17.  
  18.  
  19.     token = strtok(NULL, ".");
  20.     strcpy(mm , token);
  21.  
  22.     if ( hh == 0  )
  23.     {
  24.         printf( "%d.", hh+12 );
  25.         printf( "%sam\n", mm );
  26.     } else if ( 0 < hh && hh < 12 ) {
  27.  
  28.         printf( "%d.", hh );
  29.         printf( "%sam\n", mm );
  30.  
  31.     } else if ( 12 == hh  ) {
  32.  
  33.         printf( "%d.", hh );
  34.         printf( "%spm\n", mm );
  35.  
  36.     } else if ( 12 < hh && hh < 24) {
  37.  
  38.         printf( "%d.", hh-12 );
  39.         printf( "%spm\n", mm );
  40.     }
  41.     }
  42.  
  43.    return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement