Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int t, ca=1;
- scanf("%d", &t);
- while (t--) {
- int x, y;
- cin>>x>>y;
- char s[200];
- scanf("%s", s);
- bool visited[64][64]={false}, rep=0;
- bool Y=true, pos=true;
- int x1=x, y1=y, cnt=1;
- for (int i=0; s[i]!='\0'; i++) {
- if (s[i]=='F') {
- if (Y)
- y1+=cnt;
- else x1+=cnt;
- if (visited[x1][y1]==false) {
- visited[x1][y1]=true;
- }
- else {
- rep++;
- }
- }
- else if (s[i]=='R') {
- if (Y) {
- Y=false;
- if (pos)
- cnt=1;
- else {
- cnt=-1;
- pos=false;
- }
- }
- else {
- Y=true;
- if (pos) {
- cnt=-1;
- pos=false;
- }
- else cnt=1;
- }
- }
- else if (s[i]=='L') {
- if (Y) {
- Y=false;
- if (pos) {
- cnt=-1;
- pos=false;
- }
- else {
- cnt=1;
- pos=true;
- }
- }
- else {
- Y=true;
- if (pos) {
- cnt=1;
- }
- else {
- cnt=-1;
- }
- }
- }
- }
- printf("Case #%d: %d %d %d\n", ca++, x1, y1, rep);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement