Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdlib.h>
- #include<stdio.h>
- #include<string.h>
- char* GetChar(char ch[]);
- int main()
- {
- char ch[2200],output[2200],temp[20];
- int t,msg = 0;
- scanf("%d",&t);
- while(t--){ ///loop for test case
- gets(temp);
- scanf("%[^\n]",ch); ///scan a line
- memset(output, '\0', sizeof(output));
- while( strlen(ch) != 0){ /// loop until lenth become zero
- if(ch[0] == ' '){ /// cheak for extra space
- strcat(output," ");
- strcpy(ch,ch+1);
- }
- else {
- int ln = strcspn(ch," "); /// find length without space
- memset(temp, '\0', sizeof(temp));
- strncpy(temp,ch,ln); /// copy char for that length
- if(ln == strlen(ch)) /// if length is equal to char length then set ch lenth = 0
- memset(ch, '\0', sizeof(ch));
- else strcpy(ch,ch+ln+1); /// else delete that part
- strcpy(temp,GetChar(temp)); /// find value and copy that
- strcat(output,temp); /// add to output char
- }
- }
- printf("Message #%d\n%s\n",++msg,output);
- if(t != 0) printf("\n");
- }
- return 0;
- }
- char* GetChar(char ch[]){
- if(strcmp(ch,".-") == 0) return "A";
- else if(strcmp(ch,"-...") == 0) return "B";
- else if(strcmp(ch,"-.-.") == 0) return "C";
- else if(strcmp(ch,"-..") == 0) return "D";
- else if(strcmp(ch,".") == 0) return "E";
- else if(strcmp(ch,"..-.") == 0) return "F";
- else if(strcmp(ch,"--.") == 0) return "G";
- else if(strcmp(ch,"....") == 0) return "H";
- else if(strcmp(ch,"..") == 0) return "I";
- else if(strcmp(ch,".---") == 0) return "J";
- else if(strcmp(ch,"-.-") == 0) return "K";
- else if(strcmp(ch,".-..") == 0) return "L";
- else if(strcmp(ch,"--") == 0) return "M";
- else if(strcmp(ch,"-.") == 0) return "N";
- else if(strcmp(ch,"---") == 0) return "O";
- else if(strcmp(ch,".--.") == 0) return "P";
- else if(strcmp(ch,"--.-") == 0) return "Q";
- else if(strcmp(ch,".-.") == 0) return "R";
- else if(strcmp(ch,"...") == 0) return "S";
- else if(strcmp(ch,"-") == 0) return "T";
- else if(strcmp(ch,"..-") == 0) return "U";
- else if(strcmp(ch,"...-") == 0) return "V";
- else if(strcmp(ch,".--") == 0) return "W";
- else if(strcmp(ch,"-..-") == 0) return "X";
- else if(strcmp(ch,"-.--") == 0) return "Y";
- else if(strcmp(ch,"--..") == 0) return "Z";
- else if(strcmp(ch,".----") == 0) return "1";
- else if(strcmp(ch,"..---") == 0) return "2";
- else if(strcmp(ch,"...--") == 0) return "3";
- else if(strcmp(ch,"....-") == 0) return "4";
- else if(strcmp(ch,".....") == 0) return "5";
- else if(strcmp(ch,"-....") == 0) return "6";
- else if(strcmp(ch,"--...") == 0) return "7";
- else if(strcmp(ch,"---..") == 0) return "8";
- else if(strcmp(ch,"----.") == 0) return "9";
- else if(strcmp(ch,"-----") == 0) return "0";
- else if(strcmp(ch,".-.-.-") == 0) return ".";
- else if(strcmp(ch,"--..--") == 0) return ",";
- else if(strcmp(ch,"..--..") == 0) return "?";
- else if(strcmp(ch,".----.") == 0) return "'";
- else if(strcmp(ch,"-.-.--") == 0) return "!";
- else if(strcmp(ch,"-..-.") == 0) return "/";
- else if(strcmp(ch,"-.--.") == 0) return "(";
- else if(strcmp(ch,"-.--.-") == 0) return ")";
- else if(strcmp(ch,".-...") == 0) return "&";
- else if(strcmp(ch,"---...") == 0) return ":";
- else if(strcmp(ch,"-.-.-.") == 0) return ";";
- else if(strcmp(ch,"-...-") == 0) return "=";
- else if(strcmp(ch,".-.-.") == 0) return "+";
- else if(strcmp(ch,"-....-") == 0) return "-";
- else if(strcmp(ch,"..--.-") == 0) return "_";
- else if(strcmp(ch,".-..-.") == 0) return "\"";
- else if(strcmp(ch,".--.-.") == 0) return "@";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement