ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1243. Divorce of the Seven Dwarfs

Fastes solution O(length(st)/2),almost O(1)
Posted by ZiV 3 Jan 2006 02:37
Var
 st,s : string;
 x,y,i,j,fl : longint;
BEGIN
 Readln(st);
 if length(st) and 1 <> 0 then
  st := '0' + st;
 i := 3;
 j := length(st);
 val(copy(st,1,2),y,fl);
 y := (y mod 7)*2;
 while i < j do
  Begin
   s := copy(st,i,2);
   val(s,x,fl);
   y := ((x+y) mod 7) * 2;
   Inc(i,2);
  End;
 Writeln(y div 2);
END.