Advertisement
Guest User

Untitled

a guest
May 4th, 2015
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int N;
  10.     int M;
  11.     bool hiba;
  12.  cout << "ADATOK BEOLVASASA." << endl;
  13.  int bemod;
  14.  do {
  15.  cout << "Adja meg a beolvasas modjat! (fajlbol - 1, billentyuzetrol - 2)" << endl;
  16.  cin >> bemod;
  17.  hiba = cin.fail() || (bemod!=1) && (bemod!=2);
  18.  if (hiba){
  19.  cout << "Hibas adat!" << endl;
  20.  cin.clear(); string tmp; getline(cin, tmp, '\n');
  21.  }
  22.  }while(hiba);
  23.  if (bemod==1){
  24.     do{
  25.     cout << "Adja meg a fajl nevet" << endl;
  26.     string filename;
  27.     cin >> filename;
  28.     ifstream f(filename.c_str());
  29.     f >> N;
  30.     hiba = cin.fail() || N<2;
  31.     if (hiba) {
  32.         cout << "Hibas adat, legalabb 2 torzsnek kell lennie!" << endl;
  33.         cin.clear(); string tmp; getline(cin, tmp, '\n');
  34.     }
  35.     }while(hiba);
  36.     string T[N];
  37.     for (int i=0; i<N; i++){
  38.         f >> T[i];
  39.     }
  40.     close f;
  41.  }else{
  42.     do {
  43.     cout << "Torzsek szama:" << endl;
  44.     cin >> N;
  45.     hiba = cin.fail() || N<2;
  46.     if (hiba) {
  47.         cout << "Hibas adat, legalabb 2 torzsnek kell lennie!" << endl;
  48.         cin.clear(); string tmp; getline(cin, tmp, '\n');
  49.     }
  50.     }while(hiba);
  51.     string T[N];
  52.  
  53.     for (int i=0; i<N; i++){
  54.         cout << i+1 << ". Torzs neve:" << endl;
  55.         cin >> T[i];
  56.     }
  57.     cout << "Haboruk szama:" << endl;
  58.     cin >> M;
  59.     string X[2*M];
  60.     int Ev[2*M];
  61.     for (int j=0; j<2*M; j=j+2) {
  62.         cout << (j+2)/2 << ". Haboru resztvevoi:" << endl;
  63.         cin >> X[j];
  64.         cout << "es" << endl;
  65.         do {
  66.         cin >> X[j+1];
  67.         hiba = cin.fail() || X[j]==X[j+1];
  68.         if (hiba) {
  69.             cout << "Hibas adat, a torzs nem haboruzhat magaval" << endl;
  70.             cout << "Masik fel:" << endl;
  71.             cin.clear(); string tmp; getline(cin, tmp, '\n');
  72.         }
  73.         }while(hiba);
  74.         do {
  75.         cout << "A haboru kezdete:" << endl;
  76.         cin >> Ev[j];
  77.         hiba = cin.fail() || Ev[j]<1600 || Ev[j]>1900;
  78.         if(hiba) {
  79.             cout << "Hibas adat, csak a XVII, XVIII, XIX, szazadi haborukat nezzuk." << endl;
  80.             cin.clear(); string tmp; getline(cin, tmp, '\n');
  81.         }
  82.         }while(hiba);
  83.         do {
  84.         cout << "A haboru vege:" << endl;
  85.         cin >> Ev[j+1];
  86.         hiba = cin.fail() || Ev[j+1]<Ev[j] || Ev[j+1]>1900;
  87.         if (hiba) {
  88.             cout << "Hibas adat, a haboru nem erhet veget elobb mint hogy elkezdodott" << endl;
  89.             cin.clear(); string tmp; getline(cin, tmp, '\n');
  90.         }
  91.             }while(hiba);
  92.     }
  93.     //Z es AA feladat
  94.     for (int i=0; i<N; i++){
  95.         int j=0;
  96.             while (j<(M*2)+1 && T[i]!=X[j]){
  97.                 j++;
  98.             }
  99.             if (j>(M*2)-2){
  100.                 cout << T[i] << " egy bekes torzs." << endl;
  101.             }else{
  102.                 cout << T[i] << " nem egy bekes torzs." << endl;
  103.             }
  104.  }
  105.  
  106.     //BB feladat
  107.     int db[N];
  108.     for (int i=0; i<N; i++) {
  109.             db[i]=0;
  110.             for (int j=0; j<M*2; j++){
  111.                 if (T[i]==X[j]){
  112.                     db[i]=db[i]+1;
  113.                 }
  114.             }
  115.  
  116.     }
  117.     int szam=0;
  118.     int t=0;
  119.     for (int i=0; i<N; i++) {
  120.         if (szam<db[i]){
  121.             szam=db[i];
  122.             t=i;
  123.         }
  124.     }
  125.     cout << "A(z) " << T[t] << " torzs vivta a legtobb haborut, " << szam << " darabot." << endl;
  126.     }
  127.  
  128.  
  129.  
  130.  
  131.     return 0;
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement