LA 6802 Turtle Graphics (water question)

Source: Internet
Author: User

LA 6802 Turtle Graphics (water question)

6802-Turtle Graphics


Question:

Similar to snake games. Ask the coordinates of the end point after the given path (F-forward, L-left, R-right) and after more than two points.


Solution:

Simulate it.


Reference code:

#include 
 
  #include 
  
   #include 
   
    #include 
    
     using namespace std;const int MAXN = 100;const int dx[4] = {0, 1, 0, -1};const int dy[4] = {1, 0, -1, 0};int nCase, cCase, x, y, ans;string str;int visited[MAXN][MAXN];void init() {    memset(visited, 0, sizeof(visited));    ans = 0;}void input() {    scanf("%d%d", &x, &y);    cin >> str;}void solve() {    int direct = 0;    visited[x][y] = true;    for (int i = 0; i < str.length(); i++) {        if (str[i] == 'F') {            x += dx[direct];            y += dy[direct];            if (visited[x][y] == 1) {                ans++;            }            visited[x][y]++;        }        if (str[i] == 'L') {            direct = (direct - 1 + 4) % 4;        }        if (str[i] == 'R') {            direct = (direct + 1) % 4;        }    }    printf("Case #%d: %d %d %d\n", ++cCase, x, y, ans);}int main() {    scanf("%d", &nCase);    while (nCase--) {        init();        input();        solve();    }    return 0;}
    
   
  
 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.