Pagini recente » Cod sursa (job #1495005) | Cod sursa (job #1808498) | Cod sursa (job #3257585) | Cod sursa (job #858219) | Cod sursa (job #1920780)
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
FILE * fp;
fp = fopen("diff.in","r");
int n,m,a;
fscanf(fp,"%i",&n);
fscanf(fp,"%i",&m);
int arr[n];
for(int i = 0;i<n;i++)
{
fscanf(fp,"%i",&a);
if(a == 0)
{
arr[i] = -1;
}
else
{
arr[i] = 1;
}
}
int val[m];
for(int i = 0;i<m;i++)
{
fscanf(fp,"%i",&val[i]);
}
fclose(fp);
fp = fopen("diff.out","w");
for(int j = 0;j<m;j++)
{
a = val[j];
int x = 0;
int y = -1;
int s = 0;
bool check = false;
for(int i = 0;i<n;i++)
{
s+=arr[i];
y++;
if(a > 0)
{
if(s < 0)
{
s = 0;
x = i+1;
y = i;
}
}
else if(a == 0)
{
if(s == 2 || s == -2)
{
s = arr[i];
x = i;
y = i;
}
}
else
{
if(s > 0)
{
s = 0;
x = i + 1;
y = i;
}
}
if(s == a)
{
check = true;
break;
}
}
if(check)
{
fprintf(fp,"%i ",x+1);
fprintf(fp,"%i",y+1);
fprintf(fp,"\n");
printf("%i ",x+1);
printf("%i",y+1);
printf("\n");
}
else
{
fprintf(fp,"-1");
fprintf(fp,"\n");
printf("-1");
printf("\n");
}
}
fclose(fp);
return 0;
}