SHARE
TWEET

Untitled

a guest Jan 22nd, 2020 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstring> // strcmp( char t, char t2)
  4. #include <iomanip> //setprecisionhoz ha akarod
  5.  
  6. typedef struct verseny{
  7.  
  8. char id[6]; //string
  9. char v[15];
  10.  
  11. }verseny;
  12.  
  13. using namespace std;
  14.  
  15. int main()
  16. {   char M[15];
  17.     verseny t[500];
  18.     int i=0;
  19.     int db;
  20.     cout<<"1. feladat: Az adatok beolvasasa"<<endl;
  21.     fstream f;
  22.     f.open("valaszok.txt",ios::in);
  23.     f>>M;//megoldokulcs
  24.     while( !f.eof()  ){
  25.         f>>t[i].id;
  26.         f>>t[i].v;
  27.         i++;
  28.     }
  29.     db=i-1;
  30.     f.close();
  31.     //cout<<t[db-1].v<<endl;
  32.     cout<<"2. feladat: "<<db<<endl;
  33.     cout<<"2. feladat: Versenyzo azon: "<<endl;
  34.     char ki[6];
  35.     //cout<<t[0].id;
  36.     cin>>ki;
  37.     int j;
  38.     i=0;
  39.     while(i<db){
  40.  
  41.        if(strcmp(ki,t[i].id)==0) cout<<t[i].v<<" ezt valasszolta a kotsog"<<endl;
  42.         j=0;
  43.         //while(ki[j]==t[i].id[j])j++;
  44.         while(ki[j]!='\0'){
  45.             if(ki[j]==t[i].id[j]) j++;
  46.             else {
  47.                 j=-1;
  48.                 break;
  49.             }
  50.         }
  51.         if(j==-1)  i++;
  52.         else {
  53.                 cout<< t[i].v<<endl;
  54.                 break;
  55.             }
  56.  
  57.  
  58.     }
  59.      //i-edik helyen van a illeto megoldása
  60.     //compare???
  61.     cout<<"4. feladat:"<<endl;
  62.     cout<<M<<endl;
  63.     j=0;
  64.     while(j<14){
  65.         if(M[j]== t[i].v[j]) cout<<"f";
  66.         else cout<<" ";
  67.         j++;
  68.     }
  69.     cout<<"5. feladat: A feladat sorszama ="<<endl;
  70.     int sorsz;
  71.     cin>>sorsz;
  72.     i=0;
  73.     int helyes=0;
  74.     while(i<db){
  75.         if(M[sorsz-1]== t[i].v[sorsz-1]) helyes++;
  76.         i++;
  77.     }
  78.     cout<<"A feladatra "<<helyes<<" fo ..."<< (double)100*helyes/db   <<" % adott"<<endl;
  79.     cout<<setprecision(4)<<(double)100*helyes/db<<" % adott"<<endl;
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.     return 0;
  87. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top