Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<vector>
- #include<algorithm>
- #include<fstream>
- using namespace std;
- int main(){
- ifstream archivo;
- ofstream out("polimorfo.out");
- archivo.open("polimorfo.in",ios::in);
- int tamano,M,suma=0;
- archivo>>tamano>>M;
- vector<int>virus(tamano);
- for(int i=0;i<tamano;i++){
- archivo>>virus[i];
- if(i<M){
- suma+=virus[i];
- }
- }
- int gauss=((M+1)*M)/2;
- vector<int>prueba(M);
- int cont=1;
- vector<int>numeros(1);
- numeros[0]=0;
- if(suma==gauss){
- for(int i=0;i<M;i++){
- prueba[i]=virus[i];
- }
- sort(prueba.begin(),prueba.end());
- bool band=true;
- for(int i=0;i<M;i++){
- if(prueba[i]!=i+1){
- band=false;
- break;
- }
- }
- if(band==true){
- numeros.resize(numeros.size()+1);
- numeros[numeros.size()-1]=cont;
- }
- }
- for(int i=M-1;i<virus.size()-1;i++){
- suma+=virus[i+1];
- suma-=virus[i-(M-1)];
- cont++;
- if(suma==gauss){
- int k=0;
- for(int j= i-(M-2) ;j< i+2 ;j++,k++){
- prueba[k]=virus[j];
- }
- sort(prueba.begin(),prueba.end());
- bool band=true;
- for(int j=0;j<prueba.size();j++){
- if(prueba[j]!=j+1){
- band=false;
- break;
- }
- }
- if(band==true){
- numeros.resize(numeros.size()+1);
- numeros[numeros.size()-1]=cont;
- }
- }
- }
- out<<numeros.size()-1<<endl;
- for(int k=1;k<numeros.size();k++){
- out<<numeros[k]<<" ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement