#include <bits/stdc++.h>
using namespace std;
int main ()
{
string str;
cin >> str;
long long t;
cin >> t;
long long x = 0, y = 0;
long long len = str.size();
if (t <= len) {
for (long long i = 0; i < t; i++){
if (str[i] == 'E') {
x += 1;
}
if (str[i] == 'S') {
y -= 1;
}
if (str[i] == 'W') {
x -= 1;
}
if (str[i] == 'N') {
y += 1;
}
cout << x << ' ' << y;
}
} else if (t > len) {
for (long long i = 0; i < len; i++){
if (str[i] == 'E') {
x += 1;
}
if (str[i] == 'S') {
y -= 1;
}
if (str[i] == 'W') {
x -= 1;
}
if (str[i] == 'N') {
y += 1;
}
}
long long a = t - len;
for (long long i = 0; i < a; i++){
if (str[i] == 'E') {
x += 1;
}
if (str[i] == 'S') {
y -= 1;
}
if (str[i] == 'W') {
x -= 1;
}
if (str[i] == 'N') {
y += 1;
}
}
cout << x << ' ' << y;
}
return 0;
}
/*
11072
*/
#include <bits/stdc++.h>
using namespace std;
int main ()
{
int x = 0, y = 0;
string str;
cin >> str;
int t;
cin >> t;
int len = str.size();
if (t <= len || len >= t) {
for (int i = 0; i < t; i++) {
if (str[i] == 'E') {
x += 1;
}
if (str[i] == 'S') {
y -= 1;
}
if (str[i] == 'W') {
x -= 1;
}
if (str[i] == 'N') {
y += 1;
}
}
cout << x << ' ' << y;
return 0;
} else if (t > len) {
for (int i = 0; i < t; i++) {
if (str[i] == 'E') {
x += 1;
}
if (str[i] == 'S') {
y -= 1;
}
if (str[i] == 'W') {
x -= 1;
}
if (str[i] == 'N') {
y += 1;
}
}
int sum = t / len;
for (int i = 0; i < sum; i++){
if (str[i] == 'E') {
x += 1;
}
if (str[i] == 'S') {
y -= 1;
}
if (str[i] == 'W') {
x -= 1;
}
if (str[i] == 'N') {
y += 1;
}
}
cout << x << ' ' << y;
}
return 0;
}
/*
11072
*/
#include <bits/stdc++.h>
using namespace std;
int main ()
{
int x = 0, y = 0;
string str;
cin >> str;
int t;
cin >> t;
int len = str.size();
if (t <= len || len >= t) {
for (int i = 0; i < t; i++) {
if (str[i] == 'E') {
x += 1;
}
if (str[i] == 'S') {
y -= 1;
}
if (str[i] == 'W') {
x -= 1;
}
if (str[i] == 'N') {
y += 1;
}
}
cout << x << ' ' << y;
return 0;
} else if (t > len) {
for (int j = 1; j <= t / len; j++) {
for (int i = 0; i <= len - 1; i++) {
if (str[i] == 'E') {
x += 1;
}
if (str[i] == 'S') {
y -= 1;
}
if (str[i] == 'W') {
x -= 1;
}
if (str[i] == 'N') {
y += 1;
}
}
}
int sum = t % len;
for (int i = 0; i < sum; i++){
if (str[i] == 'E') {
x += 1;
}
if (str[i] == 'S') {
y -= 1;
}
if (str[i] == 'W') {
x -= 1;
}
if (str[i] == 'N') {
y += 1;
}
}
cout << x << ' ' << y;
}
return 0;
}
@叶安槿 不能这样直接暴力,复杂度为 O(T)
寻找周期规律,假设字符串长度 len ,如果 T < 2\times len 就直接那样暴力
否则就先跑一遍字符串,看一看执行完一个字符串的操作后位置的变化(横坐标、纵坐标增加或减少了多少),随后看看 T / len 向下取整是多少,随后用这个得数记作 q ,然后从原点遍历 q 次,每次执行一遍字符串后位置的变化
接着从头遍历字符串,共 Tmodlen 次遍历,就按着 str[i] 行动,最后输出结果即可
int len = str.size();
if (t < 2 * len) {
______//暴力做法
}
int xx = 0, yy = 0;//定义变量,每跑一次字符串位置的变化情况
for (int i = 0 ; i < len ; i++) {
if (str[i] == 'E') {
xx += 1;
}
if (str[i] == 'S') {
yy -= 1;
}
if (str[i] == 'W') {
xx -= 1;
}
if (str[i] == 'N') {
yy += 1;
}
}
//计算变化情况
x += t / len * xx;
y += t / len * yy;
//计算变化(全部完整字符串的变化)
for (int i = 0 ; i < t % len ; i++) {
if (str[i] == 'E') {
x += 1;
}
if (str[i] == 'S') {
y -= 1;
}
if (str[i] == 'W') {
x -= 1;
}
if (str[i] == 'N') {
y += 1;
}
}
//计算剩下不完整字符串的变化
/*
11072
*/
#include <bits/stdc++.h>
using namespace std;
int main ()
{
int x = 0, y = 0;
string str;
cin >> str;
int t;
cin >> t;
int len = str.size();
if (t <= len || len >= t) {
for (int i = 0; i < t; i++) {
if (str[i] == 'E') {
x += 1;
}
if (str[i] == 'S') {
y -= 1;
}
if (str[i] == 'W') {
x -= 1;
}
if (str[i] == 'N') {
y += 1;
}
}
cout << x << ' ' << y;
return 0;
} else if (t > len) {
for (int j = 1; j <= floor(t / len); j++) {
for (int i = 0; i <= len - 1; i++) {
if (str[i] == 'E') {
x += 1;
}
if (str[i] == 'S') {
y -= 1;
}
if (str[i] == 'W') {
x -= 1;
}
if (str[i] == 'N') {
y += 1;
}
}
}
int sum = t % len;
for (int i = 0; i < sum; i++){
if (str[i] == 'E') {
x += 1;
}
if (str[i] == 'S') {
y -= 1;
}
if (str[i] == 'W') {
x -= 1;
}
if (str[i] == 'N') {
y += 1;
}
}
cout << x << ' ' << y;
}
return 0;
}