fork(1) download
  1. var
  2. p: string;
  3. i, x, y, s: integer;
  4. a: array[byte, byte] of byte;
  5. begin
  6. readln(p);
  7. //
  8. i := 1; x := 128; y := 128;
  9. while (i <= length(p)) do begin
  10. //
  11. case (p[i]) of
  12. 'n': inc(x);
  13. 's': dec(x);
  14. 'w': dec(y);
  15. 'e': inc(y);
  16. else
  17. break;
  18. end;
  19. //
  20. if (0 = a[x, y]) then inc(s);
  21. a[x, y] := 1;
  22. //
  23. inc(i);
  24. end;
  25. //
  26. writeln('Result: ', s);
  27. end.
  28.  
Success #stdin #stdout 0.01s 4132KB
stdin
nenennsseewwnsnesnwnse
stdout
Result: 9