fork download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. int n, x=0, y=0;
  8. char c;
  9.  
  10. cin>>n;
  11.  
  12. for(int i=0;i<n;i++){
  13. cin>>c;
  14.  
  15. if(c=='N')
  16. y++;
  17. else if(c=='S')
  18. y--;
  19. else if(c=='E')
  20. x++;
  21. else
  22. x--;
  23. }
  24.  
  25. cout<<abs(x)+abs(y);
  26.  
  27. return 0;
  28. }
Success #stdin #stdout 0.01s 5312KB
stdin
7
NNNSSWE
stdout
1