[编程题]迷路的牛牛
迷路的牛牛
http://www.nowcoder.com/questionTerminal/fc72d3493d7e4be883e931d507352a4a
解题思路:计算l和r的次数,r-l为向右走的次数(有可能是负数,不断加4加到整数),最后对4求余,
#include<iostream>
using namespace std;
int main(){
int a;
cin>>a;
string s = "NESW";
char c;
int l =0;
int r = 0;
while(a--){
cin>>c;
if(c=='L')
l++;
else
r++;
}
int i = r-l;
while(i<0){
i+=4;
}
cout<<s[i%4];
}