76 lines
1.3 KiB
C++
76 lines
1.3 KiB
C++
/*
|
|
Nome: Mario
|
|
Cognome: Montanari
|
|
Classe: 3AIN
|
|
Data: 11/03/2025
|
|
*/
|
|
|
|
#include <iostream>
|
|
#include <cctype>
|
|
#include <cstring>
|
|
|
|
#define ALFABETO 26
|
|
|
|
#define RIGHE 5
|
|
#define COLONNE 5
|
|
|
|
#define SIZE 200+1
|
|
|
|
using namespace std;
|
|
|
|
typedef struct {
|
|
int righe;
|
|
int colonne;
|
|
} coordinate;
|
|
|
|
coordinate cerca(char carattere, char campo[][COLONNE]);
|
|
|
|
int main(void) {
|
|
char campo[RIGHE][COLONNE];
|
|
int i = 0;
|
|
|
|
for (char chr = 'a'; chr <= 'z'; chr++) {
|
|
if (chr == 'j') continue;
|
|
campo[i / COLONNE][i % COLONNE] = chr;
|
|
i++;
|
|
}
|
|
|
|
char str[SIZE];
|
|
|
|
cout << "Inserisci una frase: ";
|
|
cin.getline(str, SIZE);
|
|
|
|
cout << "Frase codificata: ";
|
|
|
|
for (int i = 0; i < strlen(str); i++) {
|
|
char carattere = str[i];
|
|
if (isalpha(carattere)) {
|
|
carattere = tolower(carattere);
|
|
if (carattere == 'j') {
|
|
carattere = 'i';
|
|
}
|
|
|
|
coordinate ris = cerca(carattere, campo);
|
|
cout << ris.righe << ris.colonne << " ";
|
|
}
|
|
}
|
|
|
|
cout << endl;
|
|
|
|
return 0;
|
|
}
|
|
|
|
coordinate cerca(char carattere, char campo[][COLONNE]) {
|
|
coordinate result;
|
|
|
|
for (int i = 0; i < RIGHE; i++) {
|
|
for (int j = 0; j < COLONNE; j++) {
|
|
if (campo[i][j] == carattere) {
|
|
result.righe = i + 1;
|
|
result.colonne = j + 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
return result;
|
|
} |