Cod sursa(job #581214)

Utilizator Rares95Rares Arnautu Rares95 Data 13 aprilie 2011 21:53:38
Problema Matrix Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.07 kb
	
  # include <cstdio>
  # include <cstring>
	using namespace std;
	
	int n, m, sol;
	int f[26], g[26], a[1001][1001];
	
	void read () {
		char cit;
		std :: freopen ( "matrix.in", "rt", stdin );
		scanf ( "%d%d", &n, &m );
		for ( int i = 1; i <= n; ++i )
			for ( int j = 1; j <= n; ++j ) {
				scanf ( " %c", &cit );
				a[i][j] = cit;
			}
		for ( int i = 1; i <= m; ++i )
			for ( int j = 1; j <= m; ++j ) {
				scanf ( " %c", &cit );
				++f[cit - 'a'];
			}
	}
	
	void write () {
		std :: freopen ( "matrix.out", "wt", stdout );
		printf ( "%d\n", sol );
	}
	
	int main () {
		read ();
		for ( int i = 1; i <= n - m + 1; ++i ) {
			for ( int j = 1; j <= n - m + 1; ++j ) {
				if ( !f[ a[i][j] - 'a' ] ) continue;
				memset ( g, 0, sizeof g );
				for ( int k = i; k < i + m; ++k ) {
					for ( int l = j; l < j + m; ++l ) {
						++g[ a[k][l] - 'a' ];
					}
				}
				int ok = 1;
				for ( int k = 0; k < 26; ++k )
					if ( f[k] != g[k] ) {
						ok = 0;
						break;
					}
				if ( ok ) ++sol;
			}
		}
		write ();
		return 0;
	}