Advertisement
Just_A_Noob_Sry

emelt_info_2008_maj

Feb 15th, 2023
572
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.25 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <set>
  5.  
  6. using namespace std;
  7.  
  8. typedef struct adatok{
  9. int ora;
  10. int perc;
  11. int tszam;
  12. string szoveg;
  13.  
  14. }ADAT;
  15. int main()
  16. {
  17.     int db;
  18.     int i;
  19.     string seged;
  20.     int maxhossz=0;
  21.     int maxhely;
  22.     int minhossz=101;
  23.     int minhely;
  24.     int egyhusz=0;
  25.     int husznegyven=0;
  26.     int kozhossz=0; ///41-60ig hosszú smsek darabszáma
  27.     int hatvannyocvan=0;
  28.     int nyocvanszaz=0;
  29.     fstream f;
  30.     f.open("sms.txt", ios::in);
  31.     f>>db;
  32.     ADAT t[db+1];
  33.     for(int i=0; i<db; i++){
  34.         f>>t[i].ora;
  35.         f>>t[i].perc;
  36.         f>>t[i].tszam;
  37.         getline(f,t[i].szoveg); ///ez a törőkaraktert olvassa be, a telefonszám után
  38.         getline(f,t[i].szoveg);
  39.  
  40.         if(t[i].szoveg.length()<=20) egyhusz++;
  41.         if(21<=t[i].szoveg.length() && t[i].szoveg.length()<=40) husznegyven++;
  42.         if(41<=t[i].szoveg.length() && t[i].szoveg.length()<=60) kozhossz++;
  43.         if(61<=t[i].szoveg.length() && t[i].szoveg.length()<=80) hatvannyocvan++;
  44.         if(81<=t[i].szoveg.length()) nyocvanszaz++;
  45.  
  46.         if(t[i].szoveg.length() < minhossz){
  47.             minhossz=t[i].szoveg.length();
  48.             minhely=i;
  49.         }
  50.         if(maxhossz<t[i].szoveg.length()){
  51.             maxhossz=t[i].szoveg.length();
  52.             maxhely=i;
  53.         }
  54.         //cout<<t[i].szoveg<<endl;
  55.     }
  56.     f.close();
  57.  
  58.     //2.feladat
  59.     cout<<"2. feladat"<<endl;
  60.     if(db<10) cout<<t[db-1].szoveg<<endl;
  61.     else cout<<t[9].szoveg<<endl;
  62.  
  63.     //3.feladat
  64.     cout<<"3. feladat"<<endl;
  65.     cout<<t[maxhely].ora<<" "<<t[maxhely].perc<<" "<<t[maxhely].tszam<<" "<<t[maxhely].szoveg<<endl;
  66.     cout<<t[minhely].ora<<" "<<t[minhely].perc<<" "<<t[minhely].tszam<<" "<<t[minhely].szoveg<<endl;
  67.  
  68.     //4.feladat
  69.     cout<<"4.feladat"<<endl;
  70.     cout<<"0-20 "<<egyhusz<<endl;
  71.     cout<<"21-40 "<<husznegyven<<endl;
  72.     cout<<"41-60 "<<kozhossz<<endl;
  73.     cout<<"61-80 "<<hatvannyocvan<<endl;
  74.     cout<<"81-100 "<< nyocvanszaz<<endl;
  75.  
  76.     //5.feladat
  77.     cout<<"5.feladat"<<endl;
  78.     int aktordb=1;
  79.     int extradb=0;
  80.     for(i=1; i<db; i++){
  81.         if(t[i].ora==t[i-1].ora){
  82.             aktordb++;
  83.         }else {
  84.             if(aktordb>10) extradb=extradb+aktordb-10;
  85.             aktordb=1;
  86.         }
  87.     }
  88.     cout<<extradb<<"-szor kell felhívnia a szolgáltatót"<<endl;
  89.  
  90.     //6.feladat
  91.     cout<<"6.feladat"<<endl;
  92.     int maxido=0;
  93.     int utolso_ido=0;
  94.     for(i=0; i<db; i++){
  95.         if(t[i].tszam==123456789 && utolso_ido==0) {
  96.             utolso_ido= t[i].ora*60+t[i].perc;
  97.         }
  98.         if(t[i].tszam==123456789 && utolso_ido !=0){
  99.             if(maxido<t[i].ora*60+t[i].perc-utolso_ido){
  100.                 maxido=t[i].ora*60+t[i].perc-utolso_ido;
  101.                 utolso_ido=t[i].ora*60+t[i].perc;
  102.                 //cout<<maxido<<endl;
  103.         }
  104.     }
  105.     }
  106.     if(maxido==0) cout<<"Nem volt elég sms"<<endl;
  107.     else cout<<"Leghosszabb eltelt idő: "<<maxido/60<<" óra "<< maxido%60<<" perc"<<endl;
  108.  
  109.     //7.feladat
  110.     cout<<"7.feladat"<<endl;
  111.     cin>>t[db].ora;
  112.     cin>>t[db].perc;
  113.     cin>>t[db].tszam;
  114.     getline(cin,seged); ///elozo int utani /n
  115.     getline(cin,t[db].szoveg);
  116.  
  117.     //cout<<t[db].szoveg<<endl;
  118.     return 0;
  119. }
  120.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement