알고리즘/알고리즘 문제풀이

Codeforces Round #806 (Div. 4) - C

b1ackhand 2022. 7. 13. 23:36

문제 출처:

https://codeforces.com/contest/1703/problem/C

 

문제 분석:

주어진 숫자와 문자열에 따라 바뀐 처음 숫자를 추적하는 단순 구현 문제

 

문제 해결:

문자열 입력받은후 그 반대로 돌려주기만 하면 되는 문제이다.

 

내 소스코드:

// freopen("input.txt", "r", stdin);
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdio.h>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <cstring>
#include <list>
#include <set>
#include <string.h>
#include <map>
#include <limits.h>
#include <stdlib.h>
#include <typeinfo>
#include <bitset>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define range(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int INF = 987654321;

int testcase;


int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> testcase;

    while (testcase--)
    {
        int n;
        int arr[102];

        cin >> n;

        for (int i = 0; i < n; i++)
        {
            int tmp;
            cin >> tmp;
            arr[i] = tmp;
        }
        int num;
        string s;
        for (int t = 0; t < n; t++)
        {
            cin >> num >> s;
            for (int i = 0; i < num; i++)
            {
                int go = 0;
                if (s[i] == 'D')
                {
                    go = 1;
                }
                else
                {
                    go = -1;
                }
                int p = arr[t] + go;
                if (p < 0)
                    p = 9;
                if (p > 9)
                    p = 0;
                arr[t] = p;
            }
        }

        for (int i = 0; i < n; i++)
        {
            cout << arr[i] << " ";
        }
        cout << "\n";
    }


    return 0;
}