Submission
Status:
----------
Subtask/Task Score:
0/100
Score: 0
User: YoruoniVamp
Problemset: กราฟสัญญาณดิจิทัล
Language: cpp
Time: 0.002 second
Submitted On: 2025-09-30 17:23:31
#include <bits/stdc++.h>
using namespace std;
void printing(string s, int size) {
char arr[size][10000];
memset(arr, '_', sizeof(arr));
int i = 0;
bool top = true;
for(int c = 0; c < s.length(); ++c) {
if (c != 0) {
// paint row
if (s[c] == s[c-1]) {
for(int x = 0; x < size; ++x) {
if (top) arr[0][i] = 'X';
else arr[size-1][i] = 'X';
i += 1;
}
--i;
}
// paint col then paint row
else {
for(int y = 0; y < size; ++y) arr[y][i] = 'X';
top = !top;
for(int x = 0; x < size; ++x) {
if (top) arr[0][i] = 'X';
else arr[size-1][i] = 'X';
i += 1;
}
--i;
}
}
// first cmds
else {
if (s[c] == '0') {
// make column
for(int y = 0; y < size; ++y) {
arr[y][0] = 'X';
}
top = !top;
// make row
for(int x = 0; x < size; ++x) {
arr[size-1][x] = 'X';
i += 1;
}
--i;
}
else {
for(int x = 0; x < size; ++x) {
arr[0][x] = 'X';
i += 1;
}
--i;
}
}
}
if (top) arr[0][i] = 'X';
else arr[size-1][i] = 'X';
i += 1;
// print
for(int y = 0; y < size; ++y) {
for(int x = 0; x < i; ++x) {
cout << arr[y][x];
}
cout << '\n';
}
}
string int_to_bin(int n) {
string a = "";
int b = 1 << 7;
while(b) {
if(b&n) a += '1';
else a += '0';
b >>= 1;
}
return a;
}
int main() {
string s;
int n;
cin >> s >> n;
if (s[0] == '1' or s[0] == '0') printing(s, n);
else {
string ppppp = "";
int temp;
for(char c : s) {
temp = int(c);
ppppp += int_to_bin(temp);
// cout << ppppp;
}printing(ppppp,n);
}
}