Skip to content

USACO 2016 December Contest Bronze Division - The Cow-Signal#

Problem link: here

Solution Author: Stefan Dascalescu

Problem Solution#

Basic implementation task, for each line, print it \(k\) times while being \(k\) times larger.

Source codes#

The source codes in C++ and Python can be seen below.

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

int main()
{
    ifstream cin("cowsignal.in");
    ofstream cout("cowsignal.out");

    vector<int> total(26);

    int n, m, k;
    cin >> n >> m >> k;

    for(int i = 1; i <= n; i++)
    {
        string s;
        cin >> s;
        string larger, strk;
        for(int j = 0; j < m; j++)
        {
            if(j == 0 || s[j] != strk.back())
            {
                for(int x = 0; x < k; x++)
                    larger += strk;
                strk.clear();
            }
            strk += s[j];
        }
        for(int x = 0; x < k; x++)
            larger += strk;
        strk.clear();
        for(int j = 1; j <= k; j++)
            cout << larger << '\n';
    }
    return 0;
}
with open("cowsignal.in", "r") as fin, open("cowsignal.out", "w") as fout:
    n, m, k = map(int, fin.readline().split())
    for _ in range(n):
        s = fin.readline().strip()
        larger = ""
        strk = ""
        for j in range(m):
            if j == 0 or s[j] != strk[-1]:
                for x in range(k):
                    larger += strk
                strk = ""
            strk += s[j]
        for x in range(k):
            larger += strk
        strk = ""
        for j in range(k):
            fout.write(larger + "\n")