Skip to content

Instantly share code, notes, and snippets.

@semreh17
Created October 6, 2023 09:46
Show Gist options
  • Save semreh17/2845d97e8c49af5f05d85ac6fae7cc30 to your computer and use it in GitHub Desktop.
Save semreh17/2845d97e8c49af5f05d85ac6fae7cc30 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
using namespace std;
int main() {
string caratteri;
ifstream nomeFile;
char carattereUguale;
nomeFile.open("caratteri.txt");
//controllo se il file é stato aperto correttamente
if (!nomeFile.is_open()) {
cerr<< "Errore nell'apertura del file." << endl;
return 1;
}
getline(nomeFile, caratteri);
size_t middleIndex = caratteri.size() / 2;
//oggetti per la divisione dell'array
vector<char> firstHalf(caratteri.begin(), caratteri.begin() + middleIndex);
vector<char> secondHalf(caratteri.begin() + middleIndex, caratteri.end());
for(int i = 0; i < firstHalf.size(); i++) {
for(int j = 0; j < secondHalf.size(); j++){
if(firstHalf[i] == secondHalf[j]) {
carattereUguale = firstHalf[i];
}
}
}
cout << carattereUguale;
nomeFile.close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment