1284A - New Year and Naming - CodeForces Solution


implementation strings *800

Please click on ads to support us..

Python Code:

n, m = map(int, input(). split())
a = list(map(str, input(). split()))
b = list(map(str, input(). split()))
s = int(input())
while s:
    c = int(input())
    print(a[c % n - 1] + b[c % m - 1])
    s -= 1

C++ Code:

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

int main()
{
    int n, m;
    cin >> n >> m;

    vector<string> s(n), t(m);

    for (int i = 0; i < n; i++)
    {
        cin >> s[i];
    }

    for (int i = 0; i < m; i++)
    {
        cin >> t[i];
    }

    int q;
    cin >> q;

    for (; q > 0; q--)
    {
        int y;
        cin >> y;

        cout << s[(y + n - 1) % n] << t[(y + m - 1) % m] << endl;
    }

    return 0;
}


Comments

Submit
0 Comments
More Questions

38E - Let's Go Rolling
171G - Mysterious numbers - 2
1183C - Computer Game
400C - Inna and Huge Candy Matrix
417A - Elimination
222A - Shooshuns and Sequence
1736A - Make A Equal to B
1736B - Playing with GCD
887C - Solution for Cube
1737C - Ela and Crickets
1741C - Minimize the Thickness
1741A - Compare T-Shirt Sizes
1741D - Masha and a Beautiful Tree
109B - Lucky Probability
1741B - Funny Permutation
1741E - Sending a Sequence Over the Network
344B - Simple Molecules
370A - Rook Bishop and King
546E - Soldier and Traveling
1741G - Kirill and Company
1200B - Block Adventure
1088B - Ehab and subtraction
1270B - Interesting Subarray
478C - Table Decorations
1304C - Air Conditioner
1311C - Perform the Combo
1519C - Berland Regional
361A - Levko and Table
5E - Bindian Signalizing
687A - NP-Hard Problem