1077 - #include<iostream> #include<algorithm>...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
#include<iostream> #include<algorithm> using namespace std; enum { SIZ = 64, ALP = 20, }; int freq[2][4]; int up[ALP]; int dn[ALP]; int num; string ec[SIZ]; string co[SIZ]; char one[26]; char mat[26]; int cnt; int genCode(int a[5]){ int b[5] = {a[0],a[1],a[2],a[3],a[4]}; sort(b, b+5); int r = 0; for(int i=0; i<5;i++){ r *= 64; r += b[i]; } return r; } bool checkFreq(int m[4]){ for (int i=0; i<4; ++i){ if (freq[0][i] != freq[1][m[i]]) return false; } return true; } bool check_and_set(char a, char b){ a -= 'A'; if (mat[a] == '?'){ mat[a] = b; return true; } return mat[a] == b; } for (int i=0; i<4; ++i){ if (!check_and_set(a[i], b[m[i]])){ return false; } } return true; } void match(int m[4]){ memset(mat, '?', sizeof(mat)); int i; for (i=0; i<num; ++i){
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
if (!pass(ec[i], co[i], m)){ return; } } ++cnt; if (cnt == 1){ memcpy(one, mat, sizeof(one)); } else { for (i=0; i<26; ++i){ if (one[i] == mat[i]) continue; one[i] = '?'; } } } void fun(){ int m[4] = {0, 1, 2, 3};
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

1077 - #include&lt;iostream&gt; #include&lt;algorithm&gt;...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online