#include <iostream>
using namespace std;
int main() {
int pattern, series_size;
while(cin >> pattern >> series_size) {
int occurrences = 0;
while(series_size --> 0) {
int num;
cin >> num;
if(num == pattern) {
occurrences += 1;
}
}
cout << occurrences << '\n';
}
return 0;
}
czas: 0:10
z ios_base::sync_with_stdio(false);
: czas 0:03
#include <iostream>
#include <sstream>
#include <iterator>
#include <algorithm>
using std::cout;
#define CHEAT_INPUT \
std::ios_base::sync_with_stdio(false); \
std::stringstream cin; \
std::copy(std::istreambuf_iterator<char>(std::cin), {}, std::ostreambuf_iterator<char> (cin)) \
int main() {
CHEAT_INPUT;
int pattern, series_size;
while(cin >> pattern >> series_size) {
int occurrences = 0;
while(series_size --> 0) {
int num;
cin >> num;
if(num == pattern) {
occurrences += 1;
}
}
cout << occurrences << '\n';
}
return 0;
}
czas: 0:02
#include <iostream>
#include <sstream>
#include <iterator>
#include <algorithm>
#include <vector>
using namespace std;
void cheat_input() {
ios_base::sync_with_stdio(false);
}
vector<int> read_input_data() {
return {
istream_iterator<int>(cin), {}
};
}
template<typename It>
int process(It &it) {
int pattern = *(it++);
int series_size = *(it++);
int occurences = 0;
while(series_size --> 0) {
int num = *(it++);
if(pattern == num) {
occurences += 1;
}
}
return occurences;
}
int main() {
cheat_input();
auto data = read_input_data();
auto it = begin(data);
while(it != end(data)) {
cout << process(it) << '\n';
}
return 0;
}
czas: 0:03, więcej nie chce mi się tego męczyć.
- Notka: używając indeksów zamiast iteratorów czas jest gorszy (0:04)
#include <iostream>
#include <sstream>
#include <iterator>
#include <algorithm>
#include <vector>
using namespace std;
void cheat_input() {
ios_base::sync_with_stdio(false);
}
vector<int> read_input_data() {
return {
istream_iterator<int>(cin), {}
};
}
template<typename Cont>
int process(Cont const &cont, size_t &pointer) {
int pattern = cont[pointer++];
int series_size = cont[pointer++];
int occurences = 0;
while(series_size --> 0) {
int num = cont[pointer++];
if(pattern == num) {
occurences += 1;
}
}
return occurences;
}
int main() {
cheat_input();
auto data = read_input_data();
size_t pointer = 0u;
while(pointer < data.size()) {
cout << process(data, pointer) << '\n';
}
return 0;
}