题解 | #坐标移动#

坐标移动

http://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29

#include <string.h>

int main()
{
    char str[10003]={0};
    int i,count=0,x=0,y=0;
    fgets(str, sizeof(str), stdin);
    for(i=0;i<10002;i++)
    {count++;
     if(str[i]==';')
     {
         switch(str[i-count+1])
         {
         case 65:
         {
             if(count==3&&48<=str[i-count+2]&&57>=str[i-count+2])
                 x=x-(str[i-count+2]-48);
          if(count==4&&48<=str[i-count+2]&&57>=str[i-count+2]&&48<=str[i-count+3]&&57>=str[i-count+3])
              x=x-(str[i-count+2]-48)*10- (str[i-count+3]-48);
          } 
         break;
         case 83:
         {
             if(count==3&&48<=str[i-count+2]&&57>=str[i-count+2])
                 y=y-(str[i-count+2]-48);
          if(count==4&&48<=str[i-count+2]&&57>=str[i-count+2]&&48<=str[i-count+3]&&57>=str[i-count+3])
              y=y-(str[i-count+2]-48)*10- (str[i-count+3]-48);
          } 
         break;
         case 87:
         {
             if(count==3&&48<=str[i-count+2]&&57>=str[i-count+2])
                 y=y+str[i-count+2]-48;
          if(count==4&&48<=str[i-count+2]&&57>=str[i-count+2]&&48<=str[i-count+3]&&57>=str[i-count+3])
              y=y+(str[i-count+2]-48)*10+ (str[i-count+3]-48);
          } 
         break;
         case 68:
         {
             if(count==3&&48<=str[i-count+2]&&57>=str[i-count+2])
                 x=x+str[i-count+2]-48;
          if(count==4&&48<=str[i-count+2]&&57>=str[i-count+2]&&48<=str[i-count+3]&&57>=str[i-count+3])
              x=x+(str[i-count+2]-48)*10+ (str[i-count+3]-48);
          } 
         break;
         default:
         break;
             }
         count=0;
         }
         
     }
    printf("%d,%d",x,y);
}
       

    

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-17 14:06
点赞 评论 收藏
分享
程序员小白条:学历和简历问题,你想走开发,现在很难的啦,尤其后端方向很难走,前端、测开,都会好很多,另外要等8月底和9月初去投日常
点赞 评论 收藏
分享
昨天 14:06
门头沟学院 Java
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务