From 8ec666796065d5669690ab4da8f809213308e84e Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Sat, 4 Apr 2020 19:16:54 +0200 Subject: Create vestigium.cc --- cpp/vestigium.cc | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 cpp/vestigium.cc (limited to 'cpp') diff --git a/cpp/vestigium.cc b/cpp/vestigium.cc new file mode 100644 index 0000000..16beec7 --- /dev/null +++ b/cpp/vestigium.cc @@ -0,0 +1,71 @@ +// Google Code Jam 2020 +#include +#include +#include + +using namespace std; + +int get_trace(const vector>& m) { + int sum{}; + for(int i = 0; i < m.size(); ++i) { + sum += m.at(i).at(i); + } + + return sum; +} + +int get_dupl_row(const vector>& m) { + int nums{}; + vector elem; + for(int i = 0; i < m.size(); ++i) { + elem.clear(); + for(int j = 0; j < m.size(); ++j) { + if(find(begin(elem), end(elem), m[i][j]) == elem.end()) { + elem.push_back(m[i][j]); + } else { + nums++; + break; + } + } + } + return nums; +} + +int get_dupl_column(const vector>& m) { + int nums{}; + vector elem; + for(int i = 0; i < m.size(); ++i) { + elem.clear(); + for(int j = 0; j < m.size(); ++j) { + if(find(begin(elem), end(elem), m[j][i]) == elem.end()) { + elem.push_back(m[j][i]); + } else { + nums++; + break; + } + } + } + return nums; +} + +int main() { + int T; + cin >> T; + + for(int _ = 0; _ < T; ++_) { + int N; + cin >> N; + vector> matrix; + for(int i = 0; i < N; ++i) { + matrix.push_back(vector{}); + int elem; + for(int j = 0; j < N; ++j) { + cin >> elem; + matrix.at(i).push_back(elem); + } + } + cout << "Case #"<< _+1<<": " << get_trace(matrix) << ' ' << get_dupl_row(matrix) << ' ' << get_dupl_column(matrix) << endl; + } + + return 0; +} -- cgit v1.2.3-18-g5258