题解:P13103 [GCJ 2019 Qualification] You Can Go Your Own Way

· · 题解

P13103 [GCJ 2019 Qualification] You Can Go Your Own Way

题意

有一个人走迷宫,走出了一种方式,题目要求我们找到一条没有与这种方式重叠的路径。

思路

题目中说会有 n-1En-1S,所以 ES 一样多,所以我们只需要他走 E,我们就走 S,他走 S,我们就走 E,这样一定能保证我们与他走的不一样。

#include<bits/stdc++.h>
#define int long long
using namespace std;
int step=0; 
signed main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        string s;
        cin>>n>>s;
        step++;
        cout<<"Case #"<<step<<": ";
        for(int i=0;i<s.size();i++)
            if(s[i]=='E') cout<<"S";
            else cout<<"E";
        cout<<"\n";
    }
    return 0;
}