Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- int main()
- {
- int N;
- int M;
- bool hiba;
- cout << "ADATOK BEOLVASASA." << endl;
- int bemod;
- do {
- cout << "Adja meg a beolvasas modjat! (fajlbol - 1, billentyuzetrol - 2)" << endl;
- cin >> bemod;
- hiba = cin.fail() || (bemod!=1) && (bemod!=2);
- if (hiba){
- cout << "Hibas adat!" << endl;
- cin.clear(); string tmp; getline(cin, tmp, '\n');
- }
- }while(hiba);
- if (bemod==1){
- do{
- cout << "Adja meg a fajl nevet" << endl;
- string filename;
- cin >> filename;
- ifstream f(filename.c_str());
- f >> N;
- hiba = cin.fail() || N<2;
- if (hiba) {
- cout << "Hibas adat, legalabb 2 torzsnek kell lennie!" << endl;
- cin.clear(); string tmp; getline(cin, tmp, '\n');
- }
- }while(hiba);
- string T[N];
- for (int i=0; i<N; i++){
- f >> T[i];
- }
- close f;
- }else{
- do {
- cout << "Torzsek szama:" << endl;
- cin >> N;
- hiba = cin.fail() || N<2;
- if (hiba) {
- cout << "Hibas adat, legalabb 2 torzsnek kell lennie!" << endl;
- cin.clear(); string tmp; getline(cin, tmp, '\n');
- }
- }while(hiba);
- string T[N];
- for (int i=0; i<N; i++){
- cout << i+1 << ". Torzs neve:" << endl;
- cin >> T[i];
- }
- cout << "Haboruk szama:" << endl;
- cin >> M;
- string X[2*M];
- int Ev[2*M];
- for (int j=0; j<2*M; j=j+2) {
- cout << (j+2)/2 << ". Haboru resztvevoi:" << endl;
- cin >> X[j];
- cout << "es" << endl;
- do {
- cin >> X[j+1];
- hiba = cin.fail() || X[j]==X[j+1];
- if (hiba) {
- cout << "Hibas adat, a torzs nem haboruzhat magaval" << endl;
- cout << "Masik fel:" << endl;
- cin.clear(); string tmp; getline(cin, tmp, '\n');
- }
- }while(hiba);
- do {
- cout << "A haboru kezdete:" << endl;
- cin >> Ev[j];
- hiba = cin.fail() || Ev[j]<1600 || Ev[j]>1900;
- if(hiba) {
- cout << "Hibas adat, csak a XVII, XVIII, XIX, szazadi haborukat nezzuk." << endl;
- cin.clear(); string tmp; getline(cin, tmp, '\n');
- }
- }while(hiba);
- do {
- cout << "A haboru vege:" << endl;
- cin >> Ev[j+1];
- hiba = cin.fail() || Ev[j+1]<Ev[j] || Ev[j+1]>1900;
- if (hiba) {
- cout << "Hibas adat, a haboru nem erhet veget elobb mint hogy elkezdodott" << endl;
- cin.clear(); string tmp; getline(cin, tmp, '\n');
- }
- }while(hiba);
- }
- //Z es AA feladat
- for (int i=0; i<N; i++){
- int j=0;
- while (j<(M*2)+1 && T[i]!=X[j]){
- j++;
- }
- if (j>(M*2)-2){
- cout << T[i] << " egy bekes torzs." << endl;
- }else{
- cout << T[i] << " nem egy bekes torzs." << endl;
- }
- }
- //BB feladat
- int db[N];
- for (int i=0; i<N; i++) {
- db[i]=0;
- for (int j=0; j<M*2; j++){
- if (T[i]==X[j]){
- db[i]=db[i]+1;
- }
- }
- }
- int szam=0;
- int t=0;
- for (int i=0; i<N; i++) {
- if (szam<db[i]){
- szam=db[i];
- t=i;
- }
- }
- cout << "A(z) " << T[t] << " torzs vivta a legtobb haborut, " << szam << " darabot." << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement