Cod sursă (job #397093)

Utilizator avatar Nemo123456 nichita Nemo123456 IP ascuns
Problemă Fotografie (clasele 9-10) Compilator cpp | 0,93 kb
Rundă Arhiva de probleme Status evaluat
Dată 25 oct. 2018 22:45:13 Scor 30
#include <fstream>
using namespace std;

ifstream fin("fotografie.in");
ofstream fout("fotografie.out");


char a[1001][1001],b[1001][1001];
int n,m,p,q,suma,n1,m1,slocal,k;

int main()
{
	fin>>n>>m;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			fin>>a[i][j];
	fin>>p>>q;
	for(int i=1;i<=p;i++)
		for(int j=1;j<=q;j++)
			{
				fin>>b[i][j];
				suma+=b[i][j];	
			}	
	
	n1=n-p+1;m1=m-q+1;	
	for(int i=1;i<=n1;i++)
		for(int j=1;j<=m1;j++)
			{
				for(int r=i;r<(i+p);r++)
					for(int g=j;g<(j+q);g++)
						slocal+=a[r][g];
				if(slocal == suma) 
					{
						for(int r=i;r<(i+p);r++)
							for(int g=j;g<(j+q);g++)
								if(a[r][g]==b[r-i+1][g-j+1]) k++;						
						if(k==p*q) fout<<i-1<<" "<<j-1<<endl;
						k=0;
					}
			slocal=0;
			}
}


/*
r g  i j p q
1 3  1 3 3 3

ab aba ccb 			0 2    		
cd cdc acd			3 1
bb bcb abb			3 3
a ababa ab
c cdcdc bd
b bcbcb da

aba
cdc
bcb

*/