Skip to content

Commit 81beb98

Browse files
authored
Punched Cards solution cpp
1 parent 6b46495 commit 81beb98

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

punchedcards.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
3+
#include <iostream>
4+
#include <vector>
5+
using namespace std;
6+
7+
int main(){
8+
int t, q = 0;
9+
cin >> t;
10+
while (q++ < t) {
11+
int n, m, i, j;
12+
cin >> n >> m;
13+
// compute the actual number of rows in the output
14+
n = (n - 1) * 2 + 3;
15+
m = (m - 1) * 2 + 3;
16+
17+
cout << "Case #" << q << ":" << endl;
18+
for (i=0;i<n;i++) {
19+
for (j=0;j<m;j++) {
20+
// handle top left corner
21+
if (i < 2 && j < 2) {
22+
cout << ".";
23+
continue;
24+
}
25+
// handle intersection coordinates
26+
if (i % 2 == 0 && j % 2 == 0) {
27+
cout << "+";
28+
continue;
29+
}
30+
// handle pipes
31+
if (i % 2 == 0 && j % 2 == 1) cout << "-";
32+
if (i % 2 == 1 && j % 2 == 0) cout << "|";
33+
34+
// everything else
35+
if ((i + j) % 2 == 0) cout << ".";
36+
}
37+
cout << endl;
38+
}
39+
}
40+
return 0;
41+
}

0 commit comments

Comments
 (0)