54 lines
1.1 KiB
C++
54 lines
1.1 KiB
C++
/*
|
|
Nome: Mario
|
|
Cognome: Montanari
|
|
*/
|
|
|
|
#include <iostream>
|
|
#include <cstring>
|
|
|
|
#define SIZE 100+1
|
|
|
|
using namespace std;
|
|
|
|
void codificaMessaggio(char dst[], const char alfDecod[], const char alfCod[]);
|
|
char *strcpy(char * const dst, const char *src);
|
|
|
|
int main(void) {
|
|
char src[SIZE];
|
|
char dst[SIZE];
|
|
const char alfDecod[] = "AaBbCcDdEeFfGgHhIiLlMmNnOoPpQqRrSsTtUuVvZz";
|
|
const char alfCod[] = "OoPpGgTtIiVvCcHhEeRrNnMmAaBbQqLlZzDdUuFfSs";
|
|
|
|
cout << "";
|
|
cin.getline(src, SIZE);
|
|
|
|
*strcpy(dst, src);
|
|
|
|
codificaMessaggio(dst, alfDecod, alfCod);
|
|
|
|
cout << "" << dst << endl;
|
|
|
|
return 0;
|
|
}
|
|
|
|
void codificaMessaggio(char dst[], const char alfDecod[], const char alfCod[]) {
|
|
for (int i = 0; i < strlen(dst); i++) {
|
|
if ((dst[i] >= 'A' && dst[i] <= 'Z') || (dst[i] >= 'a' && dst[i] <= 'z')) {
|
|
for (int j = 0; j < strlen(alfCod); j++) {
|
|
if (dst[i] == alfDecod[j]) {
|
|
dst[i] = alfCod[j];
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
char *strcpy(char * const dst, const char *src) {
|
|
size_t i;
|
|
for (i = 0; src[i] != '\0'; i++) {
|
|
dst[i] = src[i];
|
|
}
|
|
dst[i] = '\0';
|
|
return dst;
|
|
} |