Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool judgeCircle(char* moves) {
- //使用坐标轴,x轴为左右,y轴为上下
- int x=0,y=0,length=0,i;
- char *s=moves;
- //计算字符个数
- while(*moves!='\0')
- {
- length++;
- *moves++;
- }
- //进行坐标值计算
- for(i=0;i<length;i++)
- {
- switch(s[i])
- {
- case 'R': x++;break;
- case 'L': x--;break;
- case 'U': y++;break;
- case 'D': y--;break;
- }
- }
- //坐标判断
- if(x==0&&y==0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
Add Comment
Please, Sign In to add comment