fork download
  1. program washington;
  2. Uses Math;
  3. const
  4. MAXT = 10000;
  5.  
  6. type coordinate = record
  7. quadrante:string;
  8. ascissa:char;
  9. ascissanumerica:longint;
  10. ordinata:string;
  11. ordinatanumerica:longint;
  12. end;
  13.  
  14. var
  15. L, T, i, j, err: LongInt;
  16. q, ord: string;
  17. asc:char;
  18. line: AnsiString;
  19. street:array[1..2] of coordinate;
  20.  
  21. procedure readcard(var s: ansistring; var quadr:string; var x: char; var y:string);
  22. begin
  23. quadr:=s[1]+s[2];
  24. x:=s[4];
  25. if s[7]=' ' then begin y:=s[6]; s := copy(s, 8, length(s)); end
  26. else begin y:=s[6]+s[7] ; s := copy(s, 9, length(s));end;
  27. end;
  28.  
  29.  
  30. begin
  31. {
  32.   uncomment the two following lines if you want to read/write from files
  33.   assign(input, 'input.txt'); reset(input);
  34.   assign(output, 'output.txt'); rewrite(output);
  35. }
  36.  
  37. ReadLn(T);
  38. for i:=0 to T-1 do
  39. begin
  40. line:='';
  41. readln(line);
  42. for j:=1 to 2 do
  43. begin
  44. readcard(line, q, asc,ord);
  45. street[j].quadrante:=q;
  46. street[j].ascissa:=asc;
  47. street[j].ordinata:=ord;
  48. val(street[j].ordinata, street[j].ordinatanumerica,err);
  49. case street[j].ascissa of
  50. 'A' : begin street[j].ascissanumerica:=0; end;
  51. 'B' : begin street[j].ascissanumerica:=1; end;
  52. 'C' : begin street[j].ascissanumerica:=2; end;
  53. 'D' : begin street[j].ascissanumerica:=3; end;
  54. 'E' : begin street[j].ascissanumerica:=4; end;
  55. 'F' : begin street[j].ascissanumerica:=5; end;
  56. 'G' : begin street[j].ascissanumerica:=6; end;
  57. 'H' : begin street[j].ascissanumerica:=7; end;
  58. 'I' : begin street[j].ascissanumerica:=8; end;
  59. 'J' : begin street[j].ascissanumerica:=9; end;
  60. 'K' : begin street[j].ascissanumerica:=10; end;
  61. 'L' : begin street[j].ascissanumerica:=11; end;
  62. 'M' : begin street[j].ascissanumerica:=12; end;
  63. 'N' : begin street[j].ascissanumerica:=13; end;
  64. 'O' : begin street[j].ascissanumerica:=14; end;
  65. 'P' : begin street[j].ascissanumerica:=15; end;
  66. 'Q' : begin street[j].ascissanumerica:=16; end;
  67. 'R' : begin street[j].ascissanumerica:=17; end;
  68. 'S' : begin street[j].ascissanumerica:=18; end;
  69. 'T' : begin street[j].ascissanumerica:=19; end;
  70. 'U' : begin street[j].ascissanumerica:=20; end;
  71. 'V' : begin street[j].ascissanumerica:=21; end;
  72. 'W' : begin street[j].ascissanumerica:=22; end;
  73. 'X' : begin street[j].ascissanumerica:=23; end;
  74. 'Y' : begin street[j].ascissanumerica:=24; end;
  75. 'Z' : begin street[j].ascissanumerica:=25; end;
  76. end;
  77. if street[j].quadrante='NW' then street[j].ascissanumerica:=(-1)*street[j].ascissanumerica
  78. else
  79. if street[j].quadrante='SW' then
  80. begin
  81. street[j].ascissanumerica:=(-1)*street[j].ascissanumerica;
  82. if street[j].ordinatanumerica<>0 then street[j].ordinatanumerica:= street[j].ordinatanumerica-26;
  83. end
  84. else
  85. if street[j].quadrante='SE' then if street[j].ordinatanumerica<>0 then street[j].ordinatanumerica:= street[j].ordinatanumerica-26;
  86. end;
  87. L := abs(street[2].ascissanumerica -street[1].ascissanumerica)+ abs(street[2].ordinatanumerica-street[1].ordinatanumerica);
  88. WriteLn(L);
  89. end;
  90.  
  91. end.
Success #stdin #stdout 0.01s 5296KB
stdin
5
NE A 5 NE B 7
NE G 15 SW P 0
SE U 5 NW Q 10
NW A 19 SW B 3
SE Q 21 SW P 4
stdout
3
36
67
43
48