Varianta cu 26 de case-uri
#include<iostream>Varianta cu o matrice de 26 de linii
using namespace std;
int main()
{char a[100],*p,b[100]={0};
cin.get(a,100);
for(p=a;*p;p++)
switch(*p)
{case 'A' : strcat(b,"11");break;
case 'B' : strcat(b,"12");break;
case 'C' : strcat(b,"13");break;
case 'D' : strcat(b,"14");break;
case 'E' : strcat(b,"15");break;
case 'F' : strcat(b,"21");break;
case 'G' : strcat(b,"22");break;
case 'H' : strcat(b,"23");break;
case 'I' : strcat(b,"24");break;
case 'J' : strcat(b,"24");break;
case 'K' : strcat(b,"25");break;
case 'L' : strcat(b,"31");break;
case 'M' : strcat(b,"32");break;
case 'N' : strcat(b,"33");break;
case 'O' : strcat(b,"34");break;
case 'P' : strcat(b,"35");break;
case 'Q' : strcat(b,"41");break;
case 'R' : strcat(b,"42");break;
case 'S' : strcat(b,"43");break;
case 'T' : strcat(b,"44");break;
case 'U' : strcat(b,"45");break;
case 'V' : strcat(b,"51");break;
case 'W' : strcat(b,"52");break;
case 'X' : strcat(b,"53");break;
case 'Y' : strcat(b,"54");break;
case 'Z' : strcat(b,"55");break;}
cout<<b;
}
#include<iostream>Varianta mai elegantă(provided by Boss)
using namespace std;
int main()
{char t[26][3]={"11","12","13","14","15","21","22","23","24","24","25","31","32","33","34","35","41","42","43","44","45","51","52","53","54","55"};
char b[100],a[100],*p;
cin>>a;
for(p=a;*p;p++)
strcat(b,t[*p-'A']);
cout<<b;
}
#include<iostream>Varianta şi mai elegantă(provided by DlMureşan)
using namespace std;
int main()
{char l[][10]={"aa","aABCDE","aFGHiK","aLMNOP","aQRSTU","aVWXYZ"},c[100];
int x[100]={0},i,j=0,k1,k2;
cin>>c;
for(i=0;i<strlen(c);i++)
{
if(strchr("IJ",c[i]))
{ x[j]=2;
j++;
x[j]=4;
j++;
}
for(k1=1;k1<=5;k1++)
{
for(k2=1;k2<=5;k2++)
{
if(c[i]==l[k1][k2])
{
x[j]=k1;
j++;
x[j]=k2;
j++;
}
}
}
}
for(i=0;i<j;i++)
cout<<x[i];
}
#include<iostream>
using namespace std;
int main()
{char a[100],*p;
int i=0,b[100]={0},j;
cin.get(a,100);
strupr(a);
for(p=a;*p;p++)
{ if(*p<='I')
{ b[i]=(*p-'A')/5+1;i++;
b[i]=(*p-'A')%5+1;i++;
}
if(*p>'I')
{ b[i]=(*p-'A'-1)/5+1;i++;
b[i]=(*p-'A'-1)%5+1;i++;
}
}
for(j=0;j<i;j++)
cout<<b[j];
}