Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <algorithm>
- #include <vector>
- using namespace std;
- fstream f("intrare.txt");
- vector < int > v;
- int abc (int st, int dr, int mj){
- if((v[mj] % 2 != v[mj+1] %2)){ //v[mj] obligatiru par
- //cout<<"Avem "<<mj+1<<" numere pare si "<<v.size()-mj-1<<" numere impare\n";
- cout<<mj+1<<endl<<v.size()-mj-1;
- return 0;
- } else if(v[mj] % 2 != v[mj-1] %2){ //v[mj] obligatoriu impar
- //cout<<"Avem "<<mj<<" numere pare si "<<v.size()-mj<<" numere impare\n";
- cout<<mj<<endl<<v.size()-mj;
- return 0;
- } else {
- if(v[mj]%2 == 0){
- abc(mj+1,dr,(dr+mj+1)/2);
- } else {
- abc(st,mj-1,(st+mj-1)/2);
- }
- }
- }
- void findValues(){
- if(v.size() == 1){
- if(v[0] % 2 == 0){
- //cout<<"Avem un numar par";
- cout<<1<<endl<<0;
- } else {
- //cout<<"Avem un numar impar";
- cout<<0<<endl<<1;
- }
- }else if(v.size() == 2){
- if(v[0] % 2 == 0){
- if(v[1] % 2 == 0){
- //cout<<"Avem 2 numere pare";
- cout<<2<<endl<<0;
- } else {
- //cout<<"Avem 1 numar par si 1 numar impar";
- cout<<1<<endl<<1;
- }
- } else {
- //cout<<"Avem 2 numere impare";
- cout<<0<<endl<<2;
- }
- } else {
- abc(0,v.size()-1,v.size()/2);
- }
- }
- int main() {
- int n;
- f>>n;
- for(int i=0; i<n; i++){
- int tempX;
- f>>tempX;
- v.push_back(tempX);
- }
- findValues();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement