题解
2024-05-13 23:03:57
发布于:广东
7阅读
0回复
0点赞
#include <iostream>
#include <cstdio>
using namespace std;
string a;
int x_, y_;
int curx, cury;
int main(){
cin >> a;
int i;
for(i = 0; a[i] != '\0'; i++){//预处理单个命令串
if(a[i] == 'E') x_++;
else if(a[i] == 'S') y_--;
else if(a[i] == 'W') x_--;
else y_++;
}int t, len = i;
cin >> t;
curx = t / len * x_, cury = t / len * y_;//整体加
t %= len, i = 0;
while(t--){//处理剩下的操作
if(a[i] == 'E') curx++;
else if(a[i] == 'S') cury--;
else if(a[i] == 'W') curx--;
else cury++;
i++;
}cout << curx << ' ' << cury;
return 0;
}
时间复杂度:
这里空空如也
有帮助,赞一个