Created
October 6, 2023 09:46
-
-
Save semreh17/2845d97e8c49af5f05d85ac6fae7cc30 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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