Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.26 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. string string1 = "que"; //k
  7. string str1 = "k";
  8. string string2 = "adios";
  9. string str2 = "dw";
  10. string string3 = "que tal"; //ktal
  11. string str3 = "ktal";
  12. string string4 = "te quiero mucho"; //tkm
  13. string str4 = "tkm";
  14. string string5 = "gracias"; //thx
  15. string str5 = "thx";
  16. string string6 = "besos y abrazos"; //xoxo
  17. string str6 = "xoxo";
  18. string string7 = "que carajo"; //wtf
  19. string str7 = "wtf";
  20.  
  21. struct Lletra {
  22. int tecla;
  23. int rep;
  24. char car;
  25. };
  26.  
  27. int ABC = 'z' - 'a' + 1 + 12;
  28.  
  29. vector <Lletra> l;
  30. vector <int> tec = {2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9,1,2,3,4,5,6,7,8,9,10,11,12};
  31. vector <int> re = {1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,4,1,2,3,1,2,3,4,4,4,4,4,4,4,5,4,5,1,1,1};
  32. vector <char> caracters = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w',
  33. 'x','y','z','1','2','3','4','5','6','7','8','9','*','0','#'};
  34.  
  35. int r = 'Z' - 'A' + 1;
  36. int d = int('R') - int ('r');
  37.  
  38. int mat[4][3] = {1,2,3,4,5,6,7,8,9,10,11,12};
  39.  
  40. void eliminar_espais(string& s) {
  41. int n = s.length();
  42. int k = 0;
  43. if (s[0] == ' ') {
  44. while (s[k] == ' ') s.erase(k,1);
  45. }
  46. for (int i = k; i < n; ++i) {
  47. if (s[i] == ' ' and s[i+1] == ' ') {
  48. int k = i+1;
  49. while (s[k] == ' ') {
  50. s.erase(k,1);
  51. }
  52. }
  53. }
  54. }
  55. void substituir(string& s) {
  56. size_t found1 = 0, found2 = 0, found3 = 0, found4 = 0, found5 = 0, found6 = 0, found7 = 0;
  57. while (found3 != -1) {
  58. found3 = s.find(string3,found3);
  59. if (found3 != -1) {
  60. s.erase(found3,7);
  61. s.insert(found3,str3);
  62. }
  63. }
  64.  
  65. while (found3 != -1) {
  66. found7 = s.find(string7,found7);
  67. if (found7 != -1) {
  68. s.erase(found7,10);
  69. s.insert(found7,str1);
  70. }
  71. }
  72.  
  73. while (found1 != -1) {
  74. found1 = s.find(string1,found1);
  75. if (found1 != -1) {
  76. s.erase(found1,3);
  77. s.insert(found1,str1);
  78. }
  79. }
  80. while (found2 != -1) {
  81. found2 = s.find(string2,found2);
  82. if (found2 != -1) {
  83. s.erase(found2,5);
  84. s.insert(found2,str2);
  85. }
  86. }
  87. while (found4 != -1) {
  88. found4 = s.find(string4,found4);
  89. if (found4 != -1) {
  90. s.erase(found4,15);
  91. s.insert(found4,str4);
  92. }
  93. }
  94. while (found5 != -1) {
  95. found5 = s.find(string5,found5);
  96. if (found5 != -1) {
  97. s.erase(found5,7);
  98. s.insert(found5,str5);
  99. }
  100. }
  101. while (found6 != -1) {
  102. found6 = s.find(string6,found6);
  103. if (found6 != -1) {
  104. s.erase(found6,15);
  105. s.insert(found6,str6);
  106. }
  107. }
  108. }
  109. void fer_majus(Lletra a) {
  110. int i = (a.tecla-1)/3;
  111. int auxi = i;
  112. int j = (a.tecla-1)%3;
  113. int auxj=j;
  114. while (i != 3) {
  115. if (i > 3) {
  116. --i;
  117. cout << " arriba";
  118. }
  119. else {
  120. ++i;
  121. cout << " abajo";
  122. }
  123. }
  124.  
  125. while (j != 2) {
  126. if (j > 2) {
  127. --j;
  128. cout << " izquierda";
  129. }
  130. else {
  131. ++j;
  132. cout << " derecha";
  133. }
  134. }
  135. cout << " #";
  136. while ( i != auxi) {
  137. if (i < auxi){
  138. ++i;
  139. cout << " abajo";
  140. }
  141. else {
  142. --i;
  143. cout << " arriba";
  144. }
  145. }
  146. while ( j != auxj) {
  147. if (j < auxj){
  148. ++j;
  149. cout << " derecha";
  150. }
  151. else {
  152. --j;
  153. cout << " izquierda";
  154. }
  155. }
  156. cout << ' ';
  157. for (int i = 0; i < a.rep; ++i) cout << a.tecla;
  158. }
  159. void treure_majus_i_escriure(Lletra a,Lletra b) {
  160. int i = (a.tecla-1)/3;
  161. int auxi = (b.tecla-1)/3;
  162. int j = (a.tecla-1)%3;
  163. int auxj = (b.tecla-1)%3;
  164. while (i != 3) {
  165. if (i > 3) {
  166. --i;
  167. cout << " arriba";
  168. }
  169. else {
  170. ++i;
  171. cout << " abajo";
  172. }
  173. }
  174.  
  175. while (j != 2) {
  176. if (j > 2) {
  177. --j;
  178. cout << " izquierda";
  179. }
  180. else {
  181. ++j;
  182. cout << " derecha";
  183. }
  184. }
  185. cout << " #";
  186.  
  187. while ( i != auxi) {
  188. if (i < auxi){
  189. ++i;
  190. cout << " abajo";
  191. }
  192. else {
  193. --i;
  194. cout << " arriba";
  195. }
  196. }
  197. while ( j != auxj) {
  198. if (j < auxj){
  199. ++j;
  200. cout << " derecha";
  201. }
  202. else {
  203. --j;
  204. cout << " izquierda";
  205. }
  206. }
  207. cout << ' ';
  208. for (int i = 0; i < a.rep; ++i) cout << a.tecla;
  209. }
  210. void anar(Lletra a, Lletra b) {
  211. int i = (a.tecla-1)/3;
  212. int auxi = (b.tecla-1)/3;
  213. int j = (a.tecla-1)%3;
  214. int auxj = (b.tecla-1)%3;
  215. while (i != auxi) {
  216. if (i > auxi) {
  217. --i;
  218. cout << " arriba";
  219. }
  220. else {
  221. ++i;
  222. cout << " abajo";
  223. }
  224. }
  225.  
  226. while (j != auxj) {
  227. if (j > auxj) {
  228. --j;
  229. cout << " izquierda";
  230. }
  231. else {
  232. ++j;
  233. cout << " derecha";
  234. }
  235. }
  236. cout << ' ';
  237. for (int i = 0; i < b.rep; ++i) cout << b.tecla;
  238. }
  239. void com_anar(Lletra a, Lletra b, bool bul1, bool bul2) {
  240. if (bul1 and bul2) anar(a,b);
  241. else if (bul1 and !bul2) treure_majus_i_escriure(a,b);
  242. else if (!bul1 and bul2) fer_majus(b);
  243. else anar(a,b);
  244. }
  245. void go_to(Lletra a) {
  246. cout << " #";
  247. int auxi = (a.tecla-1)/3;
  248. int auxj = (a.tecla-1)%3;
  249. int i = 3; int j = 2;
  250. while (i != auxi) {
  251. if (i > auxi) {
  252. --i;
  253. cout << " arriba";
  254. }
  255. else {
  256. ++i;
  257. cout << " abajo";
  258. }
  259. }
  260.  
  261. while (j != auxj) {
  262. if (j > auxj) {
  263. --j;
  264. cout << " izquierda";
  265. }
  266. else {
  267. ++j;
  268. cout << " derecha";
  269. }
  270. }
  271. cout << " ";
  272. for (int i = 0; i < a.rep; ++i) cout << a.tecla;
  273. }
  274. void transcriure(string& s) {
  275. bool b1,b2;
  276. bool first = true;
  277. Lletra a;
  278. Lletra b;
  279. int n = s.length();
  280. for (int i = 0; i < n-1; ++i) {
  281. if ('A' <= s[i] and s[i] <= 'Z') {b1 = true; s[i] = char(int(s[i]-d));}
  282. if ('A' <= s[i+1] and s[i+1] <= 'Z') {b2 = true; s[i+1] = char(int(s[i+1]-d));}
  283. for (int j = 0; j < ABC; ++j) {
  284. if (s[i] == l[j].car) a = l[j];
  285. else if (s[i+1] == l[j].car) b = l[j];
  286. }
  287. if (first){go_to(a); first = !first;}
  288. else{com_anar(a,b,b1,b2);}
  289.  
  290. }
  291. }
  292. int main() {
  293. for (int i = 0; i < ABC; ++i) {
  294. Lletra a;
  295. a.tecla = tec[i]; a.rep = re[i];a.car = caracters[i];
  296. l.push_back(a);
  297. }
  298. int n; cin >> n;
  299. for (int i = 0; i < n; ++i) {
  300. string s; getline(cin,s);
  301. eliminar_espais(s);
  302. substituir(s);
  303. transcriure(s);
  304. }
  305. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement