Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.04 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--){         ///loop for test case
  15.         gets(temp);
  16.         scanf("%[^\n]",ch);     ///scan a line
  17.         memset(output, '\0', sizeof(output));
  18.  
  19.        while( strlen(ch) != 0){ /// loop until lenth become zero
  20.  
  21.             if(ch[0] == ' '){ /// cheak for extra space
  22.                 strcat(output," ");
  23.                 strcpy(ch,ch+1);
  24.             }
  25.             else {
  26.                 int ln = strcspn(ch," ");   /// find length without space
  27.                 memset(temp, '\0', sizeof(temp));
  28.                 strncpy(temp,ch,ln);   /// copy char for that length
  29.  
  30.                 if(ln == strlen(ch))        /// if length is equal to char length then set ch lenth = 0
  31.                     memset(ch, '\0', sizeof(ch));
  32.                 else strcpy(ch,ch+ln+1);   ///  else delete that part
  33.  
  34.                 strcpy(temp,GetChar(temp)); /// find value and copy that
  35.                 strcat(output,temp); /// add to output char
  36.             }
  37.         }
  38.  
  39.         printf("Message #%d\n%s\n",++msg,output);
  40.         if(t != 0) printf("\n");
  41.     }
  42.     return 0;
  43. }
  44.  
  45. char* GetChar(char ch[]){
  46.  
  47.          if(strcmp(ch,".-") == 0)       return "A";
  48.     else if(strcmp(ch,"-...") == 0)     return "B";
  49.     else if(strcmp(ch,"-.-.") == 0)     return "C";
  50.     else if(strcmp(ch,"-..") == 0)      return "D";
  51.     else if(strcmp(ch,".") == 0)        return "E";
  52.     else if(strcmp(ch,"..-.") == 0)     return "F";
  53.     else if(strcmp(ch,"--.") == 0)      return "G";
  54.     else if(strcmp(ch,"....") == 0)     return "H";
  55.     else if(strcmp(ch,"..") == 0)       return "I";
  56.     else if(strcmp(ch,".---") == 0)     return "J";
  57.     else if(strcmp(ch,"-.-") == 0)      return "K";
  58.     else if(strcmp(ch,".-..") == 0)     return "L";
  59.     else if(strcmp(ch,"--") == 0)       return "M";
  60.     else if(strcmp(ch,"-.") == 0)       return "N";
  61.     else if(strcmp(ch,"---") == 0)      return "O";
  62.     else if(strcmp(ch,".--.") == 0)     return "P";
  63.     else if(strcmp(ch,"--.-") == 0)     return "Q";
  64.     else if(strcmp(ch,".-.") == 0)      return "R";
  65.     else if(strcmp(ch,"...") == 0)      return "S";
  66.     else if(strcmp(ch,"-") == 0)        return "T";
  67.     else if(strcmp(ch,"..-") == 0)      return "U";
  68.     else if(strcmp(ch,"...-") == 0)     return "V";
  69.     else if(strcmp(ch,".--") == 0)      return "W";
  70.     else if(strcmp(ch,"-..-") == 0)     return "X";
  71.     else if(strcmp(ch,"-.--") == 0)     return "Y";
  72.     else if(strcmp(ch,"--..") == 0)     return "Z";
  73.     else if(strcmp(ch,".----") == 0)    return "1";
  74.     else if(strcmp(ch,"..---") == 0)    return "2";
  75.     else if(strcmp(ch,"...--") == 0)    return "3";
  76.     else if(strcmp(ch,"....-") == 0)    return "4";
  77.     else if(strcmp(ch,".....") == 0)    return "5";
  78.     else if(strcmp(ch,"-....") == 0)    return "6";
  79.     else if(strcmp(ch,"--...") == 0)    return "7";
  80.     else if(strcmp(ch,"---..") == 0)    return "8";
  81.     else if(strcmp(ch,"----.") == 0)    return "9";
  82.     else if(strcmp(ch,"-----") == 0)    return "0";
  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.     else if(strcmp(ch,"-....-") == 0)   return "-";
  97.     else if(strcmp(ch,"..--.-") == 0)   return "_";
  98.     else if(strcmp(ch,".-..-.") == 0)   return "\"";
  99.     else if(strcmp(ch,".--.-.") == 0)   return "@";
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement