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

Common Board

BYF What's wrong with my program? [1] 22 Sep 2002 19:41
SuperLong Sums
Program P1048;
  Var
    N,Temp,Plus,Temp1:Longint;
    N1,N2,S1,S2:Byte;
  Begin
    Readln(N);
    Readln(N1,N2);
    S1:=N1+N2;
    If N=1 Then
      Begin
        Write(S1);
        Halt;
      End;
    For Temp:=1 To N-1 Do
      Begin
        Readln(N1,N2);
        S2:=N1+N2;
        If S2=9 Then Inc(Plus)
          Else
            If S2>9 Then
              Begin
                If Plus<>0 Then
                  Begin
                    Write(S1+1);
                    For Temp1:=1 To Plus Do Write('0');
                    Plus:=0;
                    Dec(S2,10);
                  End
                  Else
                    Begin
                      Dec(S2,10);
                      Write(S1+1);
                    End;
              End
              Else
                Begin
                  Write(S1);
                  If Plus<>0 Then
                    Begin
                      For Temp1:=1 To Plus Do Write('9');
                      Plus:=0;
                    End;
                End;
        If Plus=0 Then S1:=S2;
      End;
    If Plus<>0 Then
      Begin
        Write(S1);
        For Temp:=1 To Plus Do Write('9');
      End
      Else Write(S2);
    Writeln;
  End.
Petar Zhivkov Petrov You have no idea, how stupid your misstake is (+) 23 Sep 2002 04:06
What about 'Plus:=0;' :)), never forget to initialize. Maybe your
compiler initializes static data to zero, but what about timus's ?