| Task: | Tietoverkko |
| Sender: | Leiska |
| Submission time: | 2018-01-18 15:51:18 +0200 |
| Language: | C++ |
| Status: | COMPILE ERROR |
Compiler report
input/code.cpp: In function 'int findv(int)':
input/code.cpp:11:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<v.size(); i++) {
^
input/code.cpp: In function 'void removesingle()':
input/code.cpp:28:16: error: expected primary-expression before '==' token
if(w[i+1]) == 1) c = 1;
^
input/code.cpp:34:16: error: expected primary-expression before '==' token
if(w[i-1]) == 1) c = 1;
^Code
#include <bits/stdc++.h>
using namespace std;
int n;
int p = 0;
vector<int> v;
vector<int> w;
int findv(int x) {
for(int i=0; i<v.size(); i++) {
if(v[i]==x) {
return i;
}
}
return -1;
}
void removesingle() {
int c = 0;
for(int i = 0; i<n+1; i++) {
if(w[i] == 1) {
p++;
int pos = findv(i);
w[i]--;
if(pos%2==0) {
w[i+1]--;
if(w[i+1]) == 1) c = 1;
v.erase(v.begin()+pos);
v.erase(v.begin()+pos+1);
}
else {
w[i-1]--;
if(w[i-1]) == 1) c = 1;
v.erase(v.begin()+pos);
v.erase(v.begin()+pos-1);
}
}
}
if(c==0) return;
removesingle();
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
cin >> n;
for(int i = 0; i<n+1; i++) w.push_back(0);
for(int i = 0; i<(n*2); i++) {
int t; cin >> t;
v.push_back(t);
w[t]++;
}
removesingle();
cout << p << endl;
}
