Advertisement
Guest User

11223

a guest
Jun 20th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <algorithm>
  3. #include <string>
  4.  
  5. using namespace std;
  6. void result(char str[]);
  7.  
  8. int main(){
  9. int tc, cases = 0, len, i, j, k, m;
  10.  
  11. scanf("%d", &tc);
  12.  
  13. while(tc--){
  14. char str[3000];
  15. char code[3000];
  16.  
  17. scanf(" %[^\n]", str);
  18. m = 0;
  19. len = strlen(str);
  20. printf("Message #%d\n", ++cases);
  21. for(i = 0; i < len; i++){
  22. if(str[i] == ' ' || i == len - 1){
  23. if(i == len -1){
  24. code[k++] = str[i];
  25. m = 1;
  26. }
  27. k = 0;
  28. result(code);
  29.  
  30. int len2 = strlen(code);
  31. for(int l = 0; l < len2; l++){
  32. code[l] = '\0';
  33. }
  34.  
  35. if(str[i + 1] == ' '){
  36. printf(" ");
  37. ++i;
  38. /*while(str[i] == ' '){
  39. ++i;
  40. printf(" ");
  41. }*/
  42. continue;
  43. }
  44. } else {
  45. code[k++] = str[i];
  46. }
  47. }
  48. printf("\n\n");
  49. }
  50. return 0;
  51. }
  52.  
  53. void result(char str[]){
  54. int i;
  55. char symbol[100] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,?'!/()&:;=+-_\"@\\"};
  56. char code[200][100] = {".-", "-...", ".-.-", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-.", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", "-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----.", ".-.-.-", "--..--", "..--..", "-.--.", "-.-.--", "-..-.", "-.-.", "-.--.-", ".-...", "---...", "-.-.-.", "-...-", ".-.-.", "-....-", "..--.-", ".-..-.", ".--.-."};
  57. for(i = 0; i < 53; i++){
  58. if(strcmp(str, code[i]) == 0){
  59. printf("%c", symbol[i]);
  60. break;
  61. }
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement