-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha.cpp
102 lines (92 loc) · 2.02 KB
/
a.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// template.cpp : Defines the entry point for the console application.
//
#include <climits>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <list>
#include <tuple>
#include <ctime>
#include <cassert>
using namespace std;
//type shortcuts
typedef long long ll;
typedef vector<ll> VI;
typedef long double DOUBLE;
typedef vector<DOUBLE> VD;
typedef vector<VD> VVD;
//constants
const DOUBLE EPS=1e-9;
const DOUBLE PI = atan(1) * 4;
const ll M = 1000000007;
//for-loop shortcut
#define rng(i,begin,end) for (ll i=begin;i<end;++i)
//scanf shortcuts
void scanll(ll &x) {ll r;scanf("%lld",&r);x=r;}
void scanstr(char *buf){scanf("%s",buf);}
void solve(vector<string> &a){
ll rn=a.size();
ll cn=a[0].size();
rng(i,0,rn){
rng(j,0,cn){
if (a[i][j]!='?'){
ll k=j-1;
while (k>=0&&a[i][k]=='?'){
a[i][k]=a[i][j];
--k;
}
k=j+1;
while (k<cn&&a[i][k]=='?'){
a[i][k]=a[i][j];
++k;
}
}
}
}
rng(i,0,rn){
if (a[i][0]!='?'){
ll j=i-1;
while (j>=0&&a[j][0]=='?'){
rng(k,0,cn){
a[j][k]=a[i][k];
}
--j;
}
j=i+1;
while (j<rn&&a[j][0]=='?'){
rng(k,0,cn){
a[j][k]=a[i][k];
}
++j;
}
}
}
}
int main()
{
ll tn;scanll(tn);
rng(ti,0,tn){
ll rn,cn;cin>>rn>>cn;
vector<string> a(rn);
rng(i,0,rn){
cin>>a[i];
}
solve(a);
cout<<"Case #"<<(ti+1)<<":"<<endl;
rng(i,0,rn){
cout<<a[i]<<endl;
}
}
return 0;
}