Advertisement
naskedvi

T2 - zad3.

Mar 10th, 2014
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. int f(std:: vector<int> v)
  5. {
  6. bool ponavlja=false;
  7. int brojac=0;
  8. for(int l=1;l<v.size();l++)
  9. {
  10. if(v[0]==v[l])
  11. {
  12. ponavlja=true;
  13. brojac++;
  14. break;
  15. }
  16. else brojac++;
  17. }
  18.  
  19. bool ne=false;
  20. if(ponavlja)
  21. {
  22. for(int i=0;i<v.size();i++)
  23. {
  24. for(int j=i;j<v.size();j+=brojac)
  25. {
  26. if(v[i]!=v[j])
  27. {
  28. ne=true;
  29. break;
  30. }
  31. }
  32. }
  33. }
  34. else brojac=0;
  35. if(ne) brojac=0;
  36. return brojac;
  37.  
  38. }
  39.  
  40. int main()
  41. {
  42. std::vector <int> brojevi;
  43. int n;
  44. std::cout << "Unesite brojeve:" << std::endl;
  45. for(;;)
  46. {
  47.  
  48. std::cin>>n;
  49. if(n==0) break;
  50. else
  51. brojevi.push_back(n);
  52. }
  53.  
  54. std::cout<<"Period je: "<<f(brojevi)<<std::endl;
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement