HDU 2414 chessboard Dance (simulation question, only to commemorate my fall)

Source: Internet
Author: User

Question

 

 

Simulation questions are also a variety of Wa. Recently I have fallen, and, IQ is getting negative !!!!!!!!

 

 

#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;char mp[10][10];int d=-1;//0shang,1xia,2zuo,3youint x,y;//weizhiint weizhi(int i,int j){    if(mp[i][j]==‘<‘){x=i,y=j,d=2;return 1;}    if(mp[i][j]==‘>‘){x=i,y=j,d=3;return 1;}    if(mp[i][j]==‘^‘){x=i,y=j,d=0;return 1;}    if(mp[i][j]==‘v‘){x=i,y=j,d=1;return 1;}    return 0;}void fangxiang(){    if(d==0)mp[x][y]=‘^‘;    else if(d==1)mp[x][y]=‘v‘;    else if(d==2)mp[x][y]=‘<‘;    else if(d==3)mp[x][y]=‘>‘;}void mov(int num){    while(num--)    {        char fro=mp[x][y];        if(d==0)        {            for(int i=x-1;i>=0;i--){            if(mp[i][y]==‘.‘){mp[i][y]=fro;break;}            else {                char tmp=mp[i][y];                mp[i][y]=fro;                fro=tmp;                }            }            if(x-1>=0)mp[x][y]=‘.‘,x--;        }        else if(d==1){            for(int i=x+1;i<8;i++){            if(mp[i][y]==‘.‘){mp[i][y]=fro;break;}            else {                char tmp=mp[i][y];                mp[i][y]=fro;                fro=tmp;                }            }            if(x+1<8)mp[x][y]=‘.‘,x++;        }        else if(d==2){            for(int i=y-1;i>=0;i--){            if(mp[x][i]==‘.‘){mp[x][i]=fro;break;}            else {                char tmp=mp[x][i];                mp[x][i]=fro;                fro=tmp;                }            }            if(y-1>=0)mp[x][y]=‘.‘,y--;        }        if(d==3){            for(int i=y+1;i<8;i++){            if(mp[x][i]==‘.‘){mp[x][i]=fro;break;}            else {                char tmp=mp[x][i];                mp[x][i]=fro;                fro=tmp;                }            }            if(y+1<8)    mp[x][y]=‘.‘,y++;        }    }}void turnn(char cc){    if(cc==‘l‘)    {        if(d==0)d=2;        else if(d==1)d=3;        else if(d==2)d=1;        else if(d==3)d=0;    }    else if(cc==‘r‘)    {         if(d==0)d=3;        else if(d==1)d=2;        else if(d==2)d=0;        else if(d==3)d=1;    }    else if(cc==‘b‘)    {        if(d==0)d=1;        else if(d==1)d=0;        else if(d==2)d=3;        else if(d==3)d=2;    }}int main(){    while(scanf("%s",mp[0])!=EOF)    {        if(strcmp(mp[0],"--")==0)break;        for(int i=1;i<8;i++)        {            scanf("%s",mp[i]);        }        int fl=0;        for(int i=0;i<8;i++){            for(int j=0;j<8;j++){                if(weizhi(i,j)){fl=1;break;}            }            if(fl)break;        }        while(1)        {            char p[10];            int movee;            scanf("%s",p);            if(strcmp(p,"#")==0)break;            if(strcmp(p,"move")==0){                scanf("%d",&movee);                mov(movee);            }            else {                scanf("%s",p);                turnn(p[0]);                fangxiang();            }        }        for(int i=0;i<8;i++)            printf("%s\n",mp[i]);                printf("\n");    }    return 0;}
View code

 

HDU 2414 chessboard Dance (simulation question, only to commemorate my fall)

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.