//Code by Patcas Csaba #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define LL long long #define PII pair #define VB vector #define VI vector #define VD vector #define VS vector #define VPII vector > #define VVI vector < VI > #define VVB vector < VB > #define FORN(i, n) for(int i = 0; i < (n); ++i) #define FOR(i, a, b) for(int i = (a); i <= (b); ++i) #define FORD(i, a, b) for(int i = (a); i >= (b); --i) #define REPEAT do{ #define UNTIL(x) }while(!(x)); #define SZ size() #define BG begin() #define EN end() #define CL clear() #define X first #define Y second #define RS resize #define PB push_back #define MP make_pair #define ALL(x) x.begin(), x.end() #define IN_FILE "a.in" #define OUT_FILE "a.out" int n, m; vector a, b; bool compresible(string s) { return s[0] == s[1] && s[2] == s[3] && s[4] == s[5]; } int val(char c) { if (c >= '0' && c <= '9') return c - '0'; else return c - 'A' + 10; } int toDec(string s) { return val(s[0]) * 16 + val(s[1]); } char next2(char c) { if (c == '9') return 'A'; else return c + 1; } char prev2(char c) { if (c == 'A') return '9'; else return c - 1; } string findBest(string s) { string ans = s.substr(0, 1) + s[0]; int bestDif = abs(toDec(ans) - toDec(s)); if (s[0] != 'F') { char hehe[5]; sprintf(hehe, "%c%c", next2(s[0]), next2(s[0])); string pos(hehe); int dif = abs(toDec(pos) - toDec(s)); if (dif < bestDif) { bestDif = dif; ans = pos; } } if (s[0] != '0') { char hehe[5]; sprintf(hehe, "%c%c", prev2(s[0]), prev2(s[0])); string pos(hehe); int dif = abs(toDec(pos) - toDec(s)); if (dif <= bestDif) { bestDif = dif; ans = pos; } } return ans.substr(0, 1); } int main() { //Read data //freopen(IN_FILE, "r", stdin); //freopen(OUT_FILE, "w", stdout); cin >> n >> m; a.RS(n + 1, VS(m + 1)); b.RS(n + 1, VS(m + 1)); FOR(i, 1, n) FOR(j, 1, m) { cin >> a[i][j]; a[i][j].erase(0, 1); if (compresible(a[i][j])) b[i][j] = a[i][j].substr(0, 1) + a[i][j].substr(2, 1) + a[i][j].substr(4, 1); else { b[i][j] = findBest(a[i][j].substr(0, 2)) + findBest(a[i][j].substr(2, 2)) + findBest(a[i][j].substr(4, 2)); } } //Solve //Write data FOR(i, 1, n) { FOR(j, 1, m) cout << "#" << b[i][j] << " "; cout << endl; } return 0; }