Created
November 25, 2013 15:10
-
-
Save dafr32/7642669 to your computer and use it in GitHub Desktop.
Matura Rozsz 2013 zad6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
#include <sstream> | |
using namespace std; | |
string intToStr (int a) | |
{ | |
ostringstream ss; | |
ss << a; | |
return ss.str(); | |
} | |
bool Rosnaca (string liczba) | |
{ | |
for(int i=1;i<liczba.length();i++) | |
{ | |
if (liczba[i]<liczba[i-1]) return false; | |
} | |
return true; | |
} | |
int Horner(string liczba) | |
{ | |
int suma=0; | |
for(int i=0;i<liczba.length();i++) | |
if( liczba[i]-48 < 10 ) | |
suma=suma*8 + (liczba[i]-48); | |
else | |
suma=suma*8 + (liczba[i]-87); | |
return suma; | |
} | |
bool PO (string liczba) | |
{ | |
if (liczba[0]==liczba[liczba.length()-1]) | |
return true; | |
else | |
return false; | |
} | |
int main() | |
{ | |
fstream plik; | |
string liczba; | |
int zadA=0,zadB=0,zadC=0,ile; | |
string lmin,lmax; | |
bool pierwsza = true; | |
plik.open("o:\\MaturaRozwiazania\\2013\\Rozsz\\dane.txt",ios::in); | |
if(plik) | |
{ | |
ile=0; | |
while (plik>>liczba) | |
{ | |
if(PO(liczba)) zadA++; | |
if(PO(intToStr(Horner(liczba)))) | |
{ | |
//cout << liczba<<" horner:"<<Horner(liczba)<<endl; | |
zadB++; | |
} | |
if(Rosnaca(liczba)) | |
{ | |
//cout <<"rosnaca:"<<liczba<<endl; | |
zadC++; | |
if(pierwsza) | |
{ | |
lmin=liczba; | |
lmax=liczba; | |
pierwsza=false; | |
} | |
if (Horner(liczba) > Horner(lmax) ) lmax = liczba; | |
if (Horner(liczba) < Horner(lmin) ) lmin = liczba; | |
} | |
} | |
plik.close(); | |
} | |
cout << "Zadanie A:"<<zadA<<endl; | |
cout << "Zadanie B:"<<zadB<<endl; | |
cout << "Zadanie C:"<<zadC<<endl; | |
cout << "Zadanie C max:"<<lmax<<endl; | |
cout << "Zadanie C min:"<<lmin<<endl; | |
return( 0 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment