Facebook
From Hot Hedgehog, 7 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 331
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <fstream>
  4. #include <string>
  5. #include <math.h>
  6. using namespace std;
  7. int f (string t)
  8. {
  9.         int i,A=0,b=0,x;
  10.         for(i=t.size()-1;i>=0;i--,b++)
  11.         {
  12.           x=t[i]-'0';
  13.           A=A+x*pow(10,b);     
  14.         }
  15.         return A;
  16. }
  17. int fx (string t)
  18. {
  19.         int i,p=0,A=0,x;
  20.         for(i=t.size()-1;i>=0;i--,p++)
  21.         {
  22.           x=t[i]-'0';
  23.           A=A+x*pow(8,p);      
  24.         }
  25.         return A;
  26. }
  27. int main()
  28. {
  29.   int i,l=0,e,c,b,l1=0,d=0,x=0,max,min,suma=0;
  30.   string txt,a;
  31.   ifstream tekst("dane.txt");
  32.   if(tekst.is_open())
  33.   {
  34.         while(tekst.good())
  35.         {
  36.           getline(tekst,txt);
  37.           if(txt.size())
  38.           {
  39.                 if(txt[0]==txt[txt.size()-1])
  40.                 l++;   
  41.           e=fx(txt);
  42.           c=e;
  43.           a="";
  44.           while(c>=1)
  45.           {
  46.                 b=c%10;
  47.                 a=char(b+'0')+a;
  48.                 c=c/10;
  49.           }
  50.           if(a[0]==a[a.size()-1])
  51.           l1++;
  52.           d=0;
  53.           for(i=0;i<txt.size()-1;i++)
  54.           {
  55.                 if(txt[i+1]>=txt[i])
  56.                 d++;
  57.           }
  58.           c=txt.size()-1;
  59.           if(d==c)
  60.           {
  61.                 suma++;
  62.       if(x==0)
  63.                 {
  64.                 max=f(txt);
  65.                 min=f(txt);
  66.                 x++;
  67.             }
  68.             else
  69.             {
  70.              if(f(txt)>max)
  71.                  max=f(txt);
  72.                  if(f(txt)<min)
  73.                  min=f(txt);   
  74.                 }
  75.         }
  76.         }
  77.     }
  78.     tekst.close();
  79.   }
  80.   cout << "Pierwsza cyfra jest rowna ostatniej - ile liczb: " << l;
  81.   cout << "\nPodpunkt b: " << l1 << endl;
  82.   cout << "Liczb tworzacych ciag: " << suma << endl;
  83.   cout << "Najwieksza z ciagu to: " << max << endl;
  84.   cout << "Najmniejsza z ciagu to: " << min << endl;
  85.   getch();
  86.   return 0;
  87. }