Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<fstream>
- #include<algorithm>
- #include<vector>
- using namespace std;
- int n,c;
- int v[20000], a[10];
- vector<int> res;
- void normalize(int v[], int n)
- {
- sort(v, v+c);
- int base = v[0];
- for(int i = 0; i < c; i++)
- v[i] -= base;
- }
- void leggiFile()
- {
- ifstream in("moosick.in");
- in >> n;
- for(int i = 0; i < n; i++)
- in >> v[i];
- in >> c;
- for(int i = 0; i < c; i++)
- in >> a[i];
- normalize(a, c);
- in.close();
- }
- void scriviRis()
- {
- ofstream out("moosick.out");
- out << res.size() << "\n";
- for(int i = 0; i < res.size(); i++)
- out << res[i] << "\n";
- out.close();
- }
- void calcola()
- {
- int w[10];
- for(int i = 0; i < n-c+1; i++)
- {
- for(int j = 0; j < c; j++)
- w[j] = v[i+j];
- normalize(w, c);
- bool equals = true;
- for(int j = 0; j < c; j++)
- if(w[j] != a[j])
- {
- equals = false;
- break;
- }
- if(equals)
- res.push_back(i+1);
- }
- }
- int main()
- {
- leggiFile();
- calcola();
- scriviRis();
- }
Add Comment
Please, Sign In to add comment