Advertisement
Guest User

UVA - 11223

a guest
Apr 28th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.71 KB | None | 0 0
  1. #include<stdlib.h>
  2. #include<stdio.h>
  3. #include<string.h>
  4.  
  5. char* GetChar(char ch[]);
  6.  
  7. int main()
  8. {
  9.     char ch[2200],output[2200],temp[20];
  10.  
  11.     int t,msg = 0;
  12.     scanf("%d",&t);
  13.  
  14.     while(t--){
  15.         gets(temp);
  16.         scanf("%[^\n]",ch);
  17.         memset(output, '\0', sizeof(output));
  18.         int h  = 20;
  19.        while( strlen(ch) != 0){
  20.  
  21.             if(ch[0] == ' '){
  22.                 strcat(output," ");
  23.                 strcpy(ch,ch+1);
  24.             }
  25.             else {
  26.                 int ln = strcspn(ch," ");   memset(temp, '\0', sizeof(temp));
  27.                 strncpy(temp,ch,ln);
  28.                 if(ln == strlen(ch))        memset(ch, '\0', sizeof(ch));
  29.                 strcpy(ch,ch+ln+1);
  30.                 strcpy(temp,GetChar(temp));
  31.                 strcat(output,temp);
  32.             }
  33.         }
  34.  
  35.         printf("Message #%d\n%s\n",++msg,output);
  36.         if(t != 0) printf("\n");
  37.     }
  38.     return 0;
  39. }
  40.  
  41. char* GetChar(char ch[]){
  42.  
  43.          if(strcmp(ch,".-") == 0)       return "A";
  44.     else if(strcmp(ch,"-...") == 0)     return "B";
  45.     else if(strcmp(ch,"-.-.") == 0)     return "C";
  46.     else if(strcmp(ch,"-..") == 0)      return "D";
  47.     else if(strcmp(ch,".") == 0)        return "E";
  48.     else if(strcmp(ch,"..-.") == 0)     return "F";
  49.     else if(strcmp(ch,"--.") == 0)      return "G";
  50.     else if(strcmp(ch,"....") == 0)     return "H";
  51.     else if(strcmp(ch,"..") == 0)       return "I";
  52.     else if(strcmp(ch,".---") == 0)     return "J";
  53.     else if(strcmp(ch,"-.-") == 0)      return "K";
  54.     else if(strcmp(ch,".-..") == 0)     return "L";
  55.     else if(strcmp(ch,"--") == 0)       return "M";
  56.     else if(strcmp(ch,"-.") == 0)       return "N";
  57.     else if(strcmp(ch,"---") == 0)      return "O";
  58.     else if(strcmp(ch,".--.") == 0)     return "P";
  59.     else if(strcmp(ch,"--.-") == 0)     return "Q";
  60.     else if(strcmp(ch,".-.") == 0)      return "R";
  61.     else if(strcmp(ch,"...") == 0)      return "S";
  62.     else if(strcmp(ch,"-") == 0)        return "T";
  63.     else if(strcmp(ch,"..-") == 0)      return "U";
  64.     else if(strcmp(ch,"...-") == 0)     return "V";
  65.     else if(strcmp(ch,".--") == 0)      return "W";
  66.     else if(strcmp(ch,"-..-") == 0)     return "X";
  67.     else if(strcmp(ch,"-.--") == 0)     return "Y";
  68.     else if(strcmp(ch,"--..") == 0)     return "Z";
  69.     else if(strcmp(ch,".----") == 0)    return "1";
  70.     else if(strcmp(ch,"..---") == 0)    return "2";
  71.     else if(strcmp(ch,"...--") == 0)    return "3";
  72.     else if(strcmp(ch,"....-") == 0)    return "4";
  73.     else if(strcmp(ch,".....") == 0)    return "5";
  74.     else if(strcmp(ch,"-....") == 0)    return "6";
  75.     else if(strcmp(ch,"--...") == 0)    return "7";
  76.     else if(strcmp(ch,"---..") == 0)    return "8";
  77.     else if(strcmp(ch,"----.") == 0)    return "9";
  78.     else if(strcmp(ch,"-----") == 0)    return "0";
  79.     else if(strcmp(ch,".-.-.-") == 0)   return ".";
  80.     else if(strcmp(ch,"--..--") == 0)   return ",";
  81.     else if(strcmp(ch,"..--..") == 0)   return "?";
  82.     else if(strcmp(ch,".----.") == 0)   return "'";
  83.     else if(strcmp(ch,"-.-.--") == 0)   return "!";
  84.     else if(strcmp(ch,"-..-.") == 0)    return "/";
  85.     else if(strcmp(ch,"-.--.") == 0)    return "(";
  86.     else if(strcmp(ch,"-.--.-") == 0)   return ")";
  87.     else if(strcmp(ch,".-...") == 0)    return "&";
  88.     else if(strcmp(ch,"---...") == 0)   return ":";
  89.     else if(strcmp(ch,"-.-.-.") == 0)   return ";";
  90.     else if(strcmp(ch,"-...-") == 0)    return "=";
  91.     else if(strcmp(ch,".-.-.") == 0)    return "+";
  92.     else if(strcmp(ch,"-....-") == 0)   return "-";
  93.     else if(strcmp(ch,"..--.-") == 0)   return "_";
  94.     else if(strcmp(ch,".-..-.") == 0)   return "\"";
  95.     else if(strcmp(ch,".--.-.") == 0)   return "@";
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement