CodeJam 2019 Q. - YouCanGoYourOwnWay

CodeJam 2019 Q. - YouCanGoYourOwnWay

四月 07, 2019

題目簡述

一個正方形,從左上角出發走到右下角,若步驟只有S(往下走)和E(往右走),則稱這條路線爲合法路線。
現在給定一個 nxn 的正方形和一條合法路線,求任意一條不和上面路線重疊的合法路線。

題目傳送門

想法

通過觀察我們可以知道合法路線一定是 n 個 S 和 n 個 E 的重複排列的其中一種。
因爲 S 和 E 的數量一樣,因此我們只要將 S 換成 E,E 換成 S 即可得到另外一條不重疊的合法路線。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
* CodeJam 2019 Qulification Round - YouCanGoYourOwnWay
* Author: ifTNT
*/
#include <iostream>
#include <string>
using namespace std;

int main(){
int t;
cin >> t;
for(int it=1; it<=t; it++){
int n;
string move;
cin >> n >> move;
cout << "Case #" << it << ": ";
for(auto i:move){
cout << (i=='E' ? 'S' : 'E');
}
cout << endl;
}
return 0;
}