我如何了解“运行时错误”的原因

时间:2019-07-17 12:02:34

标签: c++

摇摆步行:Google KickStart竞赛中的问题。

以下是问题的链接:https://codingcompetitions.withgoogle.com/kickstart/round/0000000000050ff2/0000000000150aac

我的解决方案代码如下。

我使用了非常基本的传统方法,但是我无法理解是什么导致了 运行时错误

但是令人惊讶的是,此代码在具有相同编译器(kick start网站使用的编译器)的示例测试用例中运行。

// I am maintaining a 2D array representing the given grid of squares.
//Every element is either 1/0 ; 1 : Representing that the robot has been 
//at the location before .

    #include<iostream>
    #include<string>

    using namespace std;

    int main()
    {
     int t;//testCases
     cin>>t;
     for(int tt=1;tt<=t;tt++){

         int n,r,c,rr,cc;
         cin>>n>>r>>c>>rr>>cc;
         string s;
         cin>>s;
         rr--;cc--;
         int beenThere[r][c]={};
         beenThere[rr][cc]=1;

         for(int i=0;i<n;i++){

             while(beenThere[rr][cc]==1){

             char move=s[i];
             if(move=='N'){rr--;}
             else if(move=='S'){rr++;}
             else if(move=='E'){cc++;}
             else{cc--;}

             }
             beenThere[rr][cc]=1;

         }

         cout<<"Case #"<<tt<<": "<<rr+1<<" "<<cc+1<<"\n";

     }

     return 0;    
    }

由于Sample测试用例使用相同的编译器正确地产生了正确的输出;我没想到运行时错误。请对此情况有所了解。

感谢您的时间!

0 个答案:

没有答案