Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <algorithm>
- #include <string>
- using namespace std;
- void result(char str[]);
- int main(){
- int tc, cases = 0, len, i, j, k, m;
- scanf("%d", &tc);
- while(tc--){
- char str[3000];
- char code[3000];
- scanf(" %[^\n]", str);
- m = 0;
- len = strlen(str);
- printf("Message #%d\n", ++cases);
- for(i = 0; i < len; i++){
- if(str[i] == ' ' || i == len - 1){
- if(i == len -1){
- code[k++] = str[i];
- m = 1;
- }
- k = 0;
- result(code);
- int len2 = strlen(code);
- for(int l = 0; l < len2; l++){
- code[l] = '\0';
- }
- if(str[i + 1] == ' '){
- printf(" ");
- ++i;
- /*while(str[i] == ' '){
- ++i;
- printf(" ");
- }*/
- continue;
- }
- } else {
- code[k++] = str[i];
- }
- }
- printf("\n\n");
- }
- return 0;
- }
- void result(char str[]){
- int i;
- char symbol[100] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,?'!/()&:;=+-_\"@\\"};
- char code[200][100] = {".-", "-...", ".-.-", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-.", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", "-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----.", ".-.-.-", "--..--", "..--..", "-.--.", "-.-.--", "-..-.", "-.-.", "-.--.-", ".-...", "---...", "-.-.-.", "-...-", ".-.-.", "-....-", "..--.-", ".-..-.", ".--.-."};
- for(i = 0; i < 53; i++){
- if(strcmp(str, code[i]) == 0){
- printf("%c", symbol[i]);
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement