Advertisement
erfanul007

UVa 11223

Dec 6th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.04 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #include<string>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. string a,x;
  8. int n,ln,spc,cnt,cn;
  9. cin>>n;
  10. int j,i=0,k,l,z;
  11. getchar();
  12. while(n--){
  13. i++;
  14. getline(cin, a);
  15. k=0;
  16. ln=a.size();
  17. cout<<"Message #"<<i<<endl;
  18. spc=0;
  19. cnt=0;
  20. cn=0;
  21. for(j=0;j<ln;j++){
  22. if(a[j]==' ' && a[j-1]==' '){
  23. if(cnt>0 && spc==0)
  24. cout<<" ";
  25. k++;
  26. spc++;
  27. continue;
  28. }
  29. if(cn==0 && a[j]!=' '){
  30. k=j;
  31. cn++;
  32. }
  33. if((a[j]==' ' && cn>0) || j+1==ln){
  34. l=j-k;
  35. if(j+1==ln && a[j]!=' ')
  36. l++;
  37. x.append(a,k,l);
  38. if(x.compare(".-")==0)
  39. cout<<"A";
  40. else if(x.compare("-...")==0)
  41. cout<<"B";
  42. else if(x.compare("-.-.")==0)
  43. cout<<"C";
  44. else if(x.compare("-..")==0)
  45. cout<<"D";
  46. else if(x.compare(".")==0)
  47. cout<<"E";
  48. else if(x.compare("..-.")==0)
  49. cout<<"F";
  50. else if(x.compare("--.")==0)
  51. cout<<"G";
  52. else if(x.compare("....")==0)
  53. cout<<"H";
  54. else if(x.compare("..")==0)
  55. cout<<"I";
  56. else if(x.compare(".---")==0)
  57. cout<<"J";
  58. else if(x.compare("-.-")==0)
  59. cout<<"K";
  60. else if(x.compare(".-..")==0)
  61. cout<<"L";
  62. else if(x.compare("--")==0)
  63. cout<<"M";
  64. else if(x.compare("-.")==0)
  65. cout<<"N";
  66. else if(x.compare("---")==0)
  67. cout<<"O";
  68. else if(x.compare(".--.")==0)
  69. cout<<"P";
  70. else if(x.compare("--.-")==0)
  71. cout<<"Q";
  72. else if(x.compare(".-.")==0)
  73. cout<<"R";
  74. else if(x.compare("...")==0)
  75. cout<<"S";
  76. else if(x.compare("-")==0)
  77. cout<<"T";
  78. else if(x.compare("..-")==0)
  79. cout<<"U";
  80. else if(x.compare("...-")==0)
  81. cout<<"V";
  82. else if(x.compare(".--")==0)
  83. cout<<"W";
  84. else if(x.compare("-..-")==0)
  85. cout<<"X";
  86. else if(x.compare("-.--")==0)
  87. cout<<"Y";
  88. else if(x.compare("--..")==0)
  89. cout<<"Z";
  90. else if(x.compare("-----")==0)
  91. cout<<"0";
  92. else if(x.compare(".----")==0)
  93. cout<<"1";
  94. else if(x.compare("..---")==0)
  95. cout<<"2";
  96. else if(x.compare("...--")==0)
  97. cout<<"3";
  98. else if(x.compare("....-")==0)
  99. cout<<"4";
  100. else if(x.compare(".....")==0)
  101. cout<<"5";
  102. else if(x.compare("-....")==0)
  103. cout<<"6";
  104. else if(x.compare("--...")==0)
  105. cout<<"7";
  106. else if(x.compare("---..")==0)
  107. cout<<"8";
  108. else if(x.compare("----.")==0)
  109. cout<<"9";
  110. else if(x.compare(".-.-.-")==0)
  111. cout<<".";
  112. else if(x.compare("--..--")==0)
  113. cout<<",";
  114. else if(x.compare("..--..")==0)
  115. cout<<"?";
  116. else if(x.compare(".----.")==0)
  117. cout<<"'";
  118. else if(x.compare("-.-.--")==0)
  119. cout<<"!";
  120. else if(x.compare("-..-.")==0)
  121. cout<<"/";
  122. else if(x.compare("-.--.")==0)
  123. cout<<"(";
  124. else if(x.compare("-.--.-")==0)
  125. cout<<")";
  126. else if(x.compare(".-...")==0)
  127. cout<<"&";
  128. else if(x.compare("---...")==0)
  129. cout<<":";
  130. else if(x.compare("-.-.-.")==0)
  131. cout<<";";
  132. else if(x.compare("-...-")==0)
  133. cout<<"=";
  134. else if(x.compare(".-.-.")==0)
  135. cout<<"+";
  136. else if(x.compare("-....-")==0)
  137. cout<<"-";
  138. else if(x.compare("..--.-")==0)
  139. cout<<"_";
  140. else if(x.compare(".-..-.")==0){
  141. char w='"';
  142. cout<<w;
  143. }
  144. else if(x.compare(".--.-.")==0)
  145. cout<<"@";
  146. k=j+1;
  147. cnt++;
  148. spc=0;
  149. x.clear();
  150. }
  151. }
  152. cout<<endl;
  153. if(n)
  154. cout<<endl;
  155. }
  156. return 0;
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement