Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. #include <iostream>
  2. #include<vector>
  3. #include<algorithm>
  4. #include<fstream>
  5. using namespace std;
  6.  
  7. int main(){
  8.  
  9. ifstream archivo;
  10. ofstream out("polimorfo.out");
  11. archivo.open("polimorfo.in",ios::in);
  12.  
  13.  
  14.  
  15.  
  16. int tamano,M,suma=0;
  17. archivo>>tamano>>M;
  18. vector<int>virus(tamano);
  19.  
  20. for(int i=0;i<tamano;i++){
  21. archivo>>virus[i];
  22. if(i<M){
  23. suma+=virus[i];
  24. }
  25. }
  26.  
  27. int gauss=((M+1)*M)/2;
  28. vector<int>prueba(M);
  29. int cont=1;
  30.  
  31. vector<int>numeros(1);
  32. numeros[0]=0;
  33.  
  34.  
  35.  
  36. if(suma==gauss){
  37.  
  38. for(int i=0;i<M;i++){
  39. prueba[i]=virus[i];
  40. }
  41.  
  42. sort(prueba.begin(),prueba.end());
  43. bool band=true;
  44. for(int i=0;i<M;i++){
  45. if(prueba[i]!=i+1){
  46. band=false;
  47. break;
  48. }
  49. }
  50. if(band==true){
  51. numeros.resize(numeros.size()+1);
  52. numeros[numeros.size()-1]=cont;
  53. }
  54.  
  55. }
  56.  
  57.  
  58.  
  59. for(int i=M-1;i<virus.size()-1;i++){
  60. suma+=virus[i+1];
  61. suma-=virus[i-(M-1)];
  62. cont++;
  63. if(suma==gauss){
  64.  
  65. int k=0;
  66. for(int j= i-(M-2) ;j< i+2 ;j++,k++){
  67. prueba[k]=virus[j];
  68. }
  69.  
  70. sort(prueba.begin(),prueba.end());
  71. bool band=true;
  72. for(int j=0;j<prueba.size();j++){
  73. if(prueba[j]!=j+1){
  74. band=false;
  75. break;
  76. }
  77. }
  78.  
  79. if(band==true){
  80. numeros.resize(numeros.size()+1);
  81. numeros[numeros.size()-1]=cont;
  82. }
  83.  
  84. }
  85. }
  86.  
  87. out<<numeros.size()-1<<endl;
  88. for(int k=1;k<numeros.size();k++){
  89. out<<numeros[k]<<" ";
  90. }
  91.  
  92.  
  93. return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement