You can understand the question.
To control a robot action, S, R, and l
For a function, calculate the function according to its definition, and then parse the string
# Include <iostream >#include <string> using namespace STD; string Z (INT, INT); struct point {int X; int y; int now_direction ;}; point Analysis (string); int main () {int N; int A, B; point P; // freopen ("C: \ Users \ haojian \ Desktop \ test.txt "," r ", stdin); CIN> N; For (INT I = 0; I <N; I ++) {CIN> A> B; P = analysis (Z (A, B); cout <p. x <"" <p. Y <Endl;} return 0; return 0;} Point Analysis (string s) {point P = {0, 0}; For (INT I = 0; I <S. size (); I ++) {Switch (s [I]) {Case 'r': P. now_direction = (P. now_direction + 1) % 4; break; Case 'l': P. now_direction = (P. now_direction-1) % 4; break; Case's ': Switch (P. now_direction) {Case 0: P. Y ++; break; Case 1: P. X ++; break; Case 2: P. Y --; break; Case 3: P. X --; break;} return P;} string Z (int A, int B) {string s; if (a <= 0 | B <= 0) {S = ""; Return (s) ;}else {S = "S" + z (a-B, B) + "R" + z (B-, a); Return s ;}}