fork download
  1. program div3;
  2. const max=100;
  3. maxcifre=100000;
  4. var N,i,h,Somma:integer;
  5. V, soluzione:array[1..max] of int64;
  6. resto: array[1..maxcifre] of integer;
  7. cifre :array[1..maxcifre] of integer;
  8. restocifre, contacifre, frequenza:array[1..maxcifre] of longint;
  9. contacifra, res: longint;
  10.  
  11. procedure sommacifre (a:int64);
  12. var j:longint;
  13. begin
  14. j:=1; somma:=0; contacifra:=0;
  15. while a >=1 do
  16. begin
  17. cifre[j]:= a mod 10;
  18. somma:=somma+cifre[j];
  19. j:=j+1;
  20. a:=a div 10;
  21. end;
  22. contacifra:=j-1;
  23. end;
  24.  
  25. begin
  26. readln(N);
  27. for i:=1 to N do read(V[i]); readln;
  28. for i:=1 to N do begin soluzione[i]:=0; frequenza[i]:=0; end;
  29. for i:=1 to N do
  30. begin
  31. sommacifre(V[i]);
  32. contacifre[i]:=contacifra;
  33. restocifre[i]:=somma mod 3;
  34. end;
  35.  
  36. for i:=1 to N do
  37. begin
  38. if restocifre[i]=0 then soluzione[i]:=V[i]
  39. else
  40. begin
  41. for h:=contacifre[i] downto 1 do
  42. begin
  43. resto[h]:=cifre[h] mod 3; write(resto[h]);
  44. if resto[h]=1 then frequenza[1]:=frequenza[1]+1
  45. else if resto[h]=2 then frequenza[2]:=frequenza[2]+1;
  46. end;
  47.  
  48. writeln;
  49. writeln(restocifre[i]);
  50. for h:=1 to 2 do write(frequenza[h]); writeln;
  51.  
  52. end;
  53. end;
  54. end.
  55. writeln(soluzione[i]);
  56. end;
  57. end.
  58.  
Success #stdin #stdout 0s 5316KB
stdin
1
100666
stdout
100000
1
10