Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- string string1 = "que"; //k
- string str1 = "k";
- string string2 = "adios";
- string str2 = "dw";
- string string3 = "que tal"; //ktal
- string str3 = "ktal";
- string string4 = "te quiero mucho"; //tkm
- string str4 = "tkm";
- string string5 = "gracias"; //thx
- string str5 = "thx";
- string string6 = "besos y abrazos"; //xoxo
- string str6 = "xoxo";
- string string7 = "que carajo"; //wtf
- string str7 = "wtf";
- struct Lletra {
- int tecla;
- int rep;
- char car;
- };
- int ABC = 'z' - 'a' + 1 + 12;
- vector <Lletra> l;
- 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};
- 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};
- 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',
- 'x','y','z','1','2','3','4','5','6','7','8','9','*','0','#'};
- int r = 'Z' - 'A' + 1;
- int d = int('R') - int ('r');
- int mat[4][3] = {1,2,3,4,5,6,7,8,9,10,11,12};
- void eliminar_espais(string& s) {
- int n = s.length();
- int k = 0;
- if (s[0] == ' ') {
- while (s[k] == ' ') s.erase(k,1);
- }
- for (int i = k; i < n; ++i) {
- if (s[i] == ' ' and s[i+1] == ' ') {
- int k = i+1;
- while (s[k] == ' ') {
- s.erase(k,1);
- }
- }
- }
- }
- void substituir(string& s) {
- size_t found1 = 0, found2 = 0, found3 = 0, found4 = 0, found5 = 0, found6 = 0, found7 = 0;
- while (found3 != -1) {
- found3 = s.find(string3,found3);
- if (found3 != -1) {
- s.erase(found3,7);
- s.insert(found3,str3);
- }
- }
- while (found3 != -1) {
- found7 = s.find(string7,found7);
- if (found7 != -1) {
- s.erase(found7,10);
- s.insert(found7,str1);
- }
- }
- while (found1 != -1) {
- found1 = s.find(string1,found1);
- if (found1 != -1) {
- s.erase(found1,3);
- s.insert(found1,str1);
- }
- }
- while (found2 != -1) {
- found2 = s.find(string2,found2);
- if (found2 != -1) {
- s.erase(found2,5);
- s.insert(found2,str2);
- }
- }
- while (found4 != -1) {
- found4 = s.find(string4,found4);
- if (found4 != -1) {
- s.erase(found4,15);
- s.insert(found4,str4);
- }
- }
- while (found5 != -1) {
- found5 = s.find(string5,found5);
- if (found5 != -1) {
- s.erase(found5,7);
- s.insert(found5,str5);
- }
- }
- while (found6 != -1) {
- found6 = s.find(string6,found6);
- if (found6 != -1) {
- s.erase(found6,15);
- s.insert(found6,str6);
- }
- }
- }
- void fer_majus(Lletra a) {
- int i = (a.tecla-1)/3;
- int auxi = i;
- int j = (a.tecla-1)%3;
- int auxj=j;
- while (i != 3) {
- if (i > 3) {
- --i;
- cout << " arriba";
- }
- else {
- ++i;
- cout << " abajo";
- }
- }
- while (j != 2) {
- if (j > 2) {
- --j;
- cout << " izquierda";
- }
- else {
- ++j;
- cout << " derecha";
- }
- }
- cout << " #";
- while ( i != auxi) {
- if (i < auxi){
- ++i;
- cout << " abajo";
- }
- else {
- --i;
- cout << " arriba";
- }
- }
- while ( j != auxj) {
- if (j < auxj){
- ++j;
- cout << " derecha";
- }
- else {
- --j;
- cout << " izquierda";
- }
- }
- cout << ' ';
- for (int i = 0; i < a.rep; ++i) cout << a.tecla;
- }
- void treure_majus_i_escriure(Lletra a,Lletra b) {
- int i = (a.tecla-1)/3;
- int auxi = (b.tecla-1)/3;
- int j = (a.tecla-1)%3;
- int auxj = (b.tecla-1)%3;
- while (i != 3) {
- if (i > 3) {
- --i;
- cout << " arriba";
- }
- else {
- ++i;
- cout << " abajo";
- }
- }
- while (j != 2) {
- if (j > 2) {
- --j;
- cout << " izquierda";
- }
- else {
- ++j;
- cout << " derecha";
- }
- }
- cout << " #";
- while ( i != auxi) {
- if (i < auxi){
- ++i;
- cout << " abajo";
- }
- else {
- --i;
- cout << " arriba";
- }
- }
- while ( j != auxj) {
- if (j < auxj){
- ++j;
- cout << " derecha";
- }
- else {
- --j;
- cout << " izquierda";
- }
- }
- cout << ' ';
- for (int i = 0; i < a.rep; ++i) cout << a.tecla;
- }
- void anar(Lletra a, Lletra b) {
- int i = (a.tecla-1)/3;
- int auxi = (b.tecla-1)/3;
- int j = (a.tecla-1)%3;
- int auxj = (b.tecla-1)%3;
- while (i != auxi) {
- if (i > auxi) {
- --i;
- cout << " arriba";
- }
- else {
- ++i;
- cout << " abajo";
- }
- }
- while (j != auxj) {
- if (j > auxj) {
- --j;
- cout << " izquierda";
- }
- else {
- ++j;
- cout << " derecha";
- }
- }
- cout << ' ';
- for (int i = 0; i < b.rep; ++i) cout << b.tecla;
- }
- void com_anar(Lletra a, Lletra b, bool bul1, bool bul2) {
- if (bul1 and bul2) anar(a,b);
- else if (bul1 and !bul2) treure_majus_i_escriure(a,b);
- else if (!bul1 and bul2) fer_majus(b);
- else anar(a,b);
- }
- void go_to(Lletra a) {
- cout << " #";
- int auxi = (a.tecla-1)/3;
- int auxj = (a.tecla-1)%3;
- int i = 3; int j = 2;
- while (i != auxi) {
- if (i > auxi) {
- --i;
- cout << " arriba";
- }
- else {
- ++i;
- cout << " abajo";
- }
- }
- while (j != auxj) {
- if (j > auxj) {
- --j;
- cout << " izquierda";
- }
- else {
- ++j;
- cout << " derecha";
- }
- }
- cout << " ";
- for (int i = 0; i < a.rep; ++i) cout << a.tecla;
- }
- void transcriure(string& s) {
- bool b1,b2;
- bool first = true;
- Lletra a;
- Lletra b;
- int n = s.length();
- for (int i = 0; i < n-1; ++i) {
- if ('A' <= s[i] and s[i] <= 'Z') {b1 = true; s[i] = char(int(s[i]-d));}
- if ('A' <= s[i+1] and s[i+1] <= 'Z') {b2 = true; s[i+1] = char(int(s[i+1]-d));}
- for (int j = 0; j < ABC; ++j) {
- if (s[i] == l[j].car) a = l[j];
- else if (s[i+1] == l[j].car) b = l[j];
- }
- if (first){go_to(a); first = !first;}
- else{com_anar(a,b,b1,b2);}
- }
- }
- int main() {
- for (int i = 0; i < ABC; ++i) {
- Lletra a;
- a.tecla = tec[i]; a.rep = re[i];a.car = caracters[i];
- l.push_back(a);
- }
- int n; cin >> n;
- for (int i = 0; i < n; ++i) {
- string s; getline(cin,s);
- eliminar_espais(s);
- substituir(s);
- transcriure(s);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement