666有点技术含量
2023-08-20 11:30:39
发布于:广东
14阅读
0回复
0点赞
#include <iostream>
#include <vector>
using namespace std;
struct ToyPerson {
int direction; // 0表示朝向圈内,1表示朝向圈外
string profession;
};
int main() {
int n, m;
cin >> n >> m;
vector<ToyPerson> toyPeople(n);
int firstIndex = 0;
for (int i = 0; i < n; i++) {
cin >> toyPeople[i].direction >> toyPeople[i].profession;
if (i == 0) {
firstIndex = i; // 记录第一个小人的索引位置
}
}
int currentIndex = firstIndex;
while (m--) {
int direction, steps;
cin >> direction >> steps;
if (toyPeople[currentIndex].direction == 0) { // 当前小人朝向圈内
if (direction == 0) {
currentIndex = (currentIndex - steps + n) % n; // 左数步数为负,所以需要加上n再取模
} else {
currentIndex = (currentIndex + steps) % n;
}
} else { // 当前小人朝向圈外
if (direction == 0) {
currentIndex = (currentIndex + steps) % n;
} else {
currentIndex = (currentIndex - steps + n) % n; // 右数步数为负,所以需要加上n再取模
}
}
}
cout << toyPeople[currentIndex].profession << endl;
return 0;
}
这里空空如也
有帮助,赞一个