fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int t;
  5. cin>>t;
  6. while (t--){
  7. int n,num,x=0,y=0;
  8. cin>>n;
  9. char c;
  10. while (n--){
  11. cin>>c>>num;
  12. if (c=='N')
  13. y+=num;
  14. if (c=='S')
  15. y-=num;
  16. if (c=='W')
  17. x-=num;
  18. if (c=='E')
  19. x+=num;
  20. }
  21. cout<<abs(x)+abs(y)<<endl;
  22. }
  23. return 0;
  24. }
Success #stdin #stdout 0s 3144KB
stdin
1
4
N 2
E 3
S 5
W 10
stdout
10