Created
February 7, 2019 14:37
-
-
Save fpdjsns/9bbfe5adaf339558cd0d077ee2c2f248 to your computer and use it in GitHub Desktop.
[Round 1A 2017] Problem A. Alphabet Cake : https://code.google.com/codejam/contest/5304486/dashboard#s=p0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Created by fpdjsns | |
// Copyright © 2019 fpdjsns. All rights reserved. | |
// | |
/* | |
* 시간복잡도 : O(RC) | |
* 공간복잡도 : O(RC) | |
*/ | |
#include<iostream> | |
#include<vector> | |
#include<algorithm> | |
#include<queue> | |
using namespace std; | |
int R, C; | |
// row | |
vector<vector<char>> setRow(vector<vector<char>> arr) { | |
for (int i = 0; i < R; i++) { | |
queue<int> q; | |
char c = '?'; | |
for (int j = 0; j < C; j++) { | |
if (arr[i][j] != '?') { | |
c = arr[i][j]; | |
} | |
if (c == '?') { | |
q.push(j); | |
continue; | |
} | |
arr[i][j] = c; | |
while (!q.empty()) { | |
arr[i][q.front()] = c; | |
q.pop(); | |
} | |
} | |
} | |
return arr; | |
} | |
// column | |
vector<vector<char>> setColumn(vector<vector<char>> arr) { | |
for (int j = 0; j < C; j++) { | |
queue<int> q; | |
char c = '?'; | |
for (int i = 0; i < R; i++) { | |
if (arr[i][j] != '?') { | |
c = arr[i][j]; | |
} | |
if (c == '?') { | |
q.push(i); | |
continue; | |
} | |
arr[i][j] = c; | |
while (!q.empty()) { | |
arr[q.front()][j] = c; | |
q.pop(); | |
} | |
} | |
} | |
return arr; | |
} | |
int main() { | |
int t; | |
cin >> t; | |
for (int c = 1; c <= t; c++) { | |
cin >> R >> C; | |
vector<vector<char>> arr(R, vector<char>(C)); | |
for (int i = 0; i < R; i++) { | |
for (int j = 0; j < C; j++) { | |
cin >> arr[i][j]; | |
} | |
} | |
arr = setRow(arr); | |
arr = setColumn(arr); | |
printf("Case #%d:\n", c); | |
for (int i = 0; i < R; i++) { | |
for (int j = 0; j < C; j++) { | |
printf("%c", arr[i][j]); | |
} | |
printf("\n"); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment