Last active
March 28, 2022 15:07
-
-
Save rafalw/0f07a25bed5bec39348c503d837fd380 to your computer and use it in GitHub Desktop.
Zadania maturalne (informatyka rozszerzona). Czerwiec 2016, zadanie 6. C++11/C++17
This file contains 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
Dane do zadania dostępne są po adresem: | |
https://arkusze.pl/maturalne/informatyka-2016-czerwiec-matura-rozszerzona-zalaczniki.zip |
This file contains 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 <vector> | |
#include <string> | |
#include <numeric> // -std=c++17 | |
// W <numeric> jest m. in. NWD (GCD) | |
using namespace std; | |
vector<string> liczby; | |
void wczytaj_liczby(vector<string>& tablica) { | |
ifstream plik_we("liczby.txt"); | |
string napis = ""; | |
while(getline(plik_we, napis)) { | |
tablica.push_back(napis); | |
} | |
// Dobry nawyk: | |
plik_we.close(); | |
} | |
int licz_osemkowe(vector<string>& dane) { | |
int ile = 0; | |
for (string l : dane) { | |
if (l[l.length() - 1] == 8 + 48) { | |
ile++; | |
} | |
} | |
return ile; | |
} | |
int main() { | |
wczytaj_liczby(liczby); | |
cout << licz_osemkowe(liczby) << endl; | |
return 0; | |
} |
This file contains 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 <vector> | |
#include <string> | |
#include <numeric> // -std=c++17 | |
// W <numeric> jest m. in. NWD (GCD) | |
using namespace std; | |
vector<string> liczby; | |
void wczytaj_liczby(vector<string>& tablica) { | |
ifstream plik_we("liczby.txt"); | |
string napis = ""; | |
while(getline(plik_we, napis)) { | |
tablica.push_back(napis); | |
} | |
// Dobry nawyk: | |
plik_we.close(); | |
} | |
// true gdy ciąg zawiera przynajmniej jedno zero | |
bool sprawdz_zera(string& ciag, int dlugosc) { | |
for (int i = 0; i < dlugosc; i++) { | |
if (ciag[i] == 48) { | |
return true; | |
} | |
} | |
return false; | |
} | |
int main() { | |
wczytaj_liczby(liczby); | |
int ile = 0; | |
for (string l : liczby) { | |
if (l[l.length() - 1] == 4 + 48) { | |
if (!sprawdz_zera(l, l.length() - 1)) { | |
ile++; | |
} | |
} | |
} | |
cout << ile << endl; | |
return 0; | |
} |
This file contains 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 <vector> | |
#include <string> | |
#include <numeric> // -std=c++17 | |
// W <numeric> jest m. in. NWD (GCD) | |
using namespace std; | |
vector<string> liczby; | |
void wczytaj_liczby(vector<string>& tablica) { | |
ifstream plik_we("liczby.txt"); | |
string napis = ""; | |
while(getline(plik_we, napis)) { | |
tablica.push_back(napis); | |
} | |
// Dobry nawyk: | |
plik_we.close(); | |
} | |
int main() { | |
wczytaj_liczby(liczby); | |
int ile = 0; | |
for (string l : liczby) { | |
if (l[l.length() - 1] == 2 + 48) { | |
char* tmp = new char(l.length()); | |
l.copy(tmp, l.length() - 1, 0); | |
if (stoul(tmp, nullptr, 2) % 2 == 0) { | |
ile++; | |
} | |
delete tmp; | |
} | |
} | |
cout << ile << endl; | |
return 0; | |
} |
This file contains 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 <vector> | |
#include <string> | |
#include <numeric> // -std=c++17 | |
// W <numeric> jest m. in. NWD (GCD) | |
using namespace std; | |
vector<string> liczby; | |
void wczytaj_liczby(vector<string>& tablica) { | |
ifstream plik_we("liczby.txt"); | |
string napis = ""; | |
while(getline(plik_we, napis)) { | |
tablica.push_back(napis); | |
} | |
// Dobry nawyk: | |
plik_we.close(); | |
} | |
int main() { | |
wczytaj_liczby(liczby); | |
unsigned long int suma = 0; | |
for (string l : liczby) { | |
if (l[l.length() - 1] == 8 + 48) { | |
char* tmp = new char(l.length()); | |
l.copy(tmp, l.length() - 1, 0); | |
suma += stoul(tmp, nullptr, 8); | |
delete tmp; | |
} | |
} | |
cout << suma << endl; | |
return 0; | |
} |
This file contains 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 <vector> | |
#include <string> | |
#include <numeric> // -std=c++17 | |
// W <numeric> jest m. in. NWD (GCD) | |
using namespace std; | |
struct liczba { | |
string kod; | |
unsigned long int wartosc; | |
}; | |
vector<liczba> liczby; | |
void wczytaj_liczby(vector<liczba>& tablica) { | |
ifstream plik_we("liczby.txt"); | |
string napis = ""; | |
while(getline(plik_we, napis)) { | |
char* tmp = new char(napis.length()); | |
napis.copy(tmp, napis.length() - 1, 0); | |
liczba l = { napis, stoul(tmp, nullptr, napis[napis.length() - 1] - 48) }; | |
delete tmp; | |
tablica.push_back(l); | |
} | |
// Dobry nawyk: | |
plik_we.close(); | |
} | |
int maks(vector<liczba>& tablica) { | |
int maks_ind = 0; | |
unsigned long maksw = tablica[0].wartosc; | |
for (int i = 1; i < tablica.size(); i++) { | |
if (tablica[i].wartosc > maksw) { | |
maksw = tablica[i].wartosc; | |
maks_ind = i; | |
} | |
} | |
return maks_ind; | |
} | |
int min(vector<liczba>& tablica) { | |
int min_ind = 0; | |
unsigned long minw = tablica[0].wartosc; | |
for (int i = 1; i < tablica.size(); i++) { | |
if (tablica[i].wartosc < minw) { | |
minw = tablica[i].wartosc; | |
min_ind = i; | |
} | |
} | |
return min_ind; | |
} | |
int main() { | |
wczytaj_liczby(liczby); | |
int minind = min(liczby); | |
int maksind = maks(liczby); | |
cout << "Wartość największa: " << liczby[maksind].kod << " DEC: " << liczby[maksind].wartosc << endl; | |
cout << "Wartość najmniejsza: " << liczby[minind].kod << " DEC: " << liczby[minind].wartosc << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment