Cod sursa(job #2664464)

Utilizator razvan_taudorTaudor Cristian Razvan razvan_taudor Data 28 octombrie 2020 18:05:49
Problema Fructe Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <iostream>
#include <fstream>
using namespace std;

int main() {
	
	ifstream f("fructe.in");
	ofstream g("fructe.out");

	int nr_teste;
	f >> nr_teste;
	int raspuns[100];
	for (int i = 1; i <= nr_teste; i++) {

		int p, q, x, y;
		f >> p >> q;
		int v[200];
		x = p;
		y = q;
		int j = 1;
		while (x != 0)
		{
			v[j] = 1;
			j++;
			x--;
		}
		while (y != 0) {
			v[j] = 2;
			j++;
			y--;
		}

		j = 1;
		int s = 0;
		while (j <= p + q) {
			 s = v[j] + v[j + 1];
			if (s == 2 || s == 4) {
				v[j + 1] = 1;
				j++;
			}
			else
			{
				v[j + 1] = 2;
				j++;
			}
			
		}

		raspuns[i] = v[p + q];
	}

	for (int i = 1; i <= nr_teste; i++) {
		if (raspuns[i] == 1) {
			g << "0" << endl;
		}
		else
		{
			g << "1" << endl;
		}
	}


	return 0;
}