Facebook
From Tinct Agouti, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 257
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. int ilosc(int l){
  6.         ifstream slowa("slowa.txt");
  7.         int ilosc=0;
  8.         string str;
  9.         while(!slowa.eof()){
  10.                 slowa>>str;
  11.                 if(str.size() == l)
  12.                         ilosc++;
  13.         }
  14.         slowa.close();
  15.         return ilosc;
  16. }
  17.  
  18. string mirror(string str){
  19.         for(int i=0; i<str.size()/2; i++){
  20.                 char h=str[i];
  21.                 str[i]=str[str.size()-i-1];
  22.                 str[str.size()-i-1]=h;
  23.         }
  24.         return str;
  25. }
  26.  
  27. int main(){
  28.         ifstream slowa;
  29.         ifstream nowe;
  30.         ofstream wyniki("wyniki_04.txt");
  31.         string strS, strN;
  32.         // 5.1
  33.         wyniki<<"5.1\n";
  34.         for(int i=1; i<=12; i++)
  35.                 wyniki<<i<<" "<<ilosc(i)<<endl;
  36.        
  37.         // 5.2
  38.         wyniki<<"\n5.2\n";
  39.         nowe.open("nowe.txt");
  40.         for(int i=0; i<25; i++){
  41.                 int ilosc=0, mirrorAmount=0;
  42.                 nowe>>strN;
  43.                 slowa.open("slowa.txt");
  44.                 for(int j=0; j<1000; j++){
  45.                         slowa>>strS;
  46.                         if(strS == strN)
  47.                                 ilosc++;
  48.                         if(strS == mirror(strN))
  49.                                 mirrorAmount++;
  50.                 }
  51.                 slowa.close();
  52.                 wyniki<<strN<<" "<<ilosc<<" "<<mirrorAmount<<endl;
  53.         }
  54.         nowe.close();
  55.        
  56.         wyniki.close();
  57.         return 0;
  58. }