Submission

Status:
P-PP---P-P

Score: 50

User: Namkhing

Problemset: กราฟสัญญาณดิจิทัล

Language: cpp

Time: 0.003 second

Submitted On: 2025-04-12 17:16:45

#include <bits/stdc++.h>
using namespace std;

string convert(int n) {
    string s = "";
    while (n) {
        int v = n & 1;
        s.push_back(v + '0');
        n >>= 1;
    }
    while (s.size() < 8) s.push_back('0');
    reverse(s.begin(), s.end());
    return s;
}

int main() {
    cin.tie(nullptr)->ios_base::sync_with_stdio(false);
    string s;
    cin >> s;
    if (s[0] != '0' && s[0] != '1') {
        string t = "";
        for (char c : s) t += convert(c);
        s = t;
    }
    int n = s.size();
    int k;
    cin >> k; k--;
    vector<vector<char>> a(k + 1, vector<char>(n * k + 1, '_'));
    int now = '1', add = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] != now) {
            for (int j = 0; j <= k; j++) a[j][add] = 'X';
        }
        now = s[i];
        int x;
        if (now == '1') x = 0;
        else x = k;
        for (int j = 0; j < k; j++) a[x][add+j] = 'X';
        add += k;
    }
    if (now == '1') a[0][add] = 'X';
    else a[k][add] = 'X';
    for (int i = 0; i <= k; i++) {
        for (int j = 0; j <= n * k; j++) cout << a[i][j]; cout << "\n";
    }
}