Skip to content

Instantly share code, notes, and snippets.

@rafalw
Last active March 28, 2022 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafalw/ff1631a058c0240e3e3509698b4ce4f3 to your computer and use it in GitHub Desktop.
Save rafalw/ff1631a058c0240e3e3509698b4ce4f3 to your computer and use it in GitHub Desktop.
Zadania maturalne (informatyka rozszerzona). Maj 2014, zadanie 5. C++11/C++17
Dane do zadania dostępne są pod adresem:
https://arkusze.pl/maturalne/informatyka-2014-maj-matura-rozszerzona-zalaczniki.zip
#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> napisy;
bool liczba_pierwsza(int liczba) {
for(int i = 2; i <= liczba / 2; i++) {
if(liczba % i == 0) {
return false;
}
}
return true;
}
int suma_ascii(string& napis) {
int suma = 0;
for(int i = 0; i < napis.length(); i++) {
suma += (char)napis[i];
}
return suma;
}
int napis_pierwszy_licz(vector<string>& dane) {
int ile = 0;
for (string l : dane) {
if (liczba_pierwsza(suma_ascii(l))) {
ile++;
}
}
return ile;
}
void wczytaj_napisy(vector<string>& tablica) {
ifstream plik_we("NAPIS.TXT");
string napis = "";
while(getline(plik_we, napis)) {
tablica.push_back(napis);
}
// Dobry nawyk:
plik_we.close();
}
int main() {
wczytaj_napisy(napisy);
cout << napis_pierwszy_licz(napisy) << endl;
return 0;
}
#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> napisy;
void wczytaj_napisy(vector<string>& tablica) {
ifstream plik_we("NAPIS.TXT");
string napis = "";
while(getline(plik_we, napis)) {
tablica.push_back(napis);
}
// Dobry nawyk:
plik_we.close();
}
bool napis_rosnacy(string& napis) {
for (int i = 0; i < napis.length() - 1; i++) {
if (napis[i] >= napis[i+1]) {
return false;
}
}
return true;
}
int main() {
wczytaj_napisy(napisy);
for (string l : napisy) {
if (napis_rosnacy(l)) {
cout << l << endl;
}
}
return 0;
}
#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> napisy;
void wczytaj_napisy(vector<string>& tablica) {
ifstream plik_we("NAPIS.TXT");
string napis = "";
while(getline(plik_we, napis)) {
tablica.push_back(napis);
}
// Dobry nawyk:
plik_we.close();
}
int main() {
wczytaj_napisy(napisy);
for (int i = 0; i < napisy.size(); i++) {
for (int j = i + 1; j < napisy.size(); j++) {
if (napisy[i] == napisy[j]) {
cout << napisy[i] << endl;
break;
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment