Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <algorithm>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. fstream f("intrare.txt");
  9. vector < int > v;
  10.  
  11.  
  12. int abc (int st, int dr, int mj){
  13.  
  14. if((v[mj] % 2 != v[mj+1] %2)){ //v[mj] obligatiru par
  15. //cout<<"Avem "<<mj+1<<" numere pare si "<<v.size()-mj-1<<" numere impare\n";
  16. cout<<mj+1<<endl<<v.size()-mj-1;
  17. return 0;
  18. } else if(v[mj] % 2 != v[mj-1] %2){ //v[mj] obligatoriu impar
  19. //cout<<"Avem "<<mj<<" numere pare si "<<v.size()-mj<<" numere impare\n";
  20. cout<<mj<<endl<<v.size()-mj;
  21. return 0;
  22. } else {
  23. if(v[mj]%2 == 0){
  24. abc(mj+1,dr,(dr+mj+1)/2);
  25. } else {
  26. abc(st,mj-1,(st+mj-1)/2);
  27. }
  28. }
  29.  
  30. }
  31. void findValues(){
  32. if(v.size() == 1){
  33. if(v[0] % 2 == 0){
  34. //cout<<"Avem un numar par";
  35. cout<<1<<endl<<0;
  36. } else {
  37. //cout<<"Avem un numar impar";
  38. cout<<0<<endl<<1;
  39. }
  40. }else if(v.size() == 2){
  41. if(v[0] % 2 == 0){
  42. if(v[1] % 2 == 0){
  43. //cout<<"Avem 2 numere pare";
  44. cout<<2<<endl<<0;
  45. } else {
  46. //cout<<"Avem 1 numar par si 1 numar impar";
  47. cout<<1<<endl<<1;
  48. }
  49. } else {
  50. //cout<<"Avem 2 numere impare";
  51. cout<<0<<endl<<2;
  52. }
  53. } else {
  54. abc(0,v.size()-1,v.size()/2);
  55. }
  56. }
  57. int main() {
  58.  
  59. int n;
  60. f>>n;
  61. for(int i=0; i<n; i++){
  62. int tempX;
  63. f>>tempX;
  64. v.push_back(tempX);
  65. }
  66. findValues();
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement