Advertisement
mehazava

X y 1 2

Jan 19th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. program project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6. {$IFDEF UNIX}{$IFDEF UseCThreads}
  7. cthreads,
  8. {$ENDIF}{$ENDIF}
  9. Classes
  10. { you can add units after this };
  11.  
  12. var
  13. inp,outp: text;
  14. x,y,i,z,raz: longint;
  15. r,s: integer;
  16. a,b,c: array[0..10000] of byte;
  17. flag1: boolean;
  18. k: char;
  19.  
  20. begin
  21. assignfile(inp,'input.txt');
  22. assignfile(outp,'output.txt');
  23. rewrite(outp);
  24. reset(inp);
  25. flag1:=false;
  26. x:=0;
  27. y:=0;
  28. repeat
  29. inc(x);
  30. read(inp,k);
  31. a[x]:=ord(k)-48;
  32. until EOLn(inp);
  33. readln(inp);
  34. repeat
  35. inc(y);
  36. read(inp,k);
  37. b[y]:=ord(k)-48;
  38. until EOLn(inp);
  39. if x>=y then begin
  40. z:=x;
  41. raz:=x-y;
  42. r:=0;
  43. for i:=z downto 1 do begin
  44. if (i-raz>=1) then s:=r+a[i]+b[i-raz]
  45. else s:=r+a[i];
  46. c[i]:=s mod 10;
  47. r:=s div 10;
  48. end;
  49. end else begin
  50. z:=y;
  51. raz:=y-x;
  52. r:=0;
  53. for i:=z downto 1 do begin
  54. if (i-raz>=1) then s:=r+a[i-raz]+b[i]
  55. else s:=r+b[i];
  56. c[i]:=s mod 10;
  57. r:=s div 10;
  58. end;
  59. end;
  60. if (r>0) then write(outp,r);
  61. for i:=1 to z do write(outp,c[i]);
  62. closefile(outp);
  63. closefile(inp);
  64. end.
  65.  
  66. Y
  67. program project1;
  68.  
  69. {$mode objfpc}{$H+}
  70.  
  71. uses
  72. {$IFDEF UNIX}{$IFDEF UseCThreads}
  73. cthreads,
  74. {$ENDIF}{$ENDIF}
  75. Classes
  76. { you can add units after this };
  77.  
  78. var
  79. inp,outp: text;
  80. x,y,i,j,z,raz,r,s,d: longint;
  81. a,b: array[0..3000] of byte;
  82. c: array[0..6001] of longint;
  83. flag1: boolean;
  84. k: char;
  85.  
  86. begin
  87. assignfile(inp,'input.txt');
  88. assignfile(outp,'output.txt');
  89. rewrite(outp);
  90. reset(inp);
  91. flag1:=false;
  92. x:=0;
  93. y:=0;
  94. repeat
  95. inc(x);
  96. read(inp,k);
  97. a[x]:=ord(k)-48;
  98. until EOLn(inp);
  99. readln(inp);
  100. repeat
  101. inc(y);
  102. read(inp,k);
  103. b[y]:=ord(k)-48;
  104. until EOLn(inp);
  105. for i:=0 to 6001 do c[i]:=0;
  106. for j:=0 to (y-1) do begin
  107. r:=0;
  108. for i:=0 to (x-1) do begin
  109. d:=6000-i-j;
  110. s:=a[x-i]*b[y-j]+r+c[d];
  111. c[d]:=s mod 10;
  112. r:=s div 10;
  113. end;
  114. c[d-1]+=r;
  115. end;
  116. r:=c[d-1] div 10;
  117. c[d-1]:=c[d-1] mod 10;
  118. i:=1;
  119. while (r>0) do begin
  120. inc(i);
  121. c[d-i]:=r mod 10;
  122. r:=r div 10;
  123. end;
  124. d:=-1;
  125. repeat
  126. inc(d);
  127. until c[d]<>0;
  128. for i:=d to 6000 do write(outp,c[i]);
  129. closefile(outp);
  130. closefile(inp);
  131. end.
  132.  
  133. 1
  134. program project1;
  135.  
  136. {$mode objfpc}{$H+}
  137.  
  138. uses
  139. {$IFDEF UNIX}{$IFDEF UseCThreads}
  140. cthreads,
  141. {$ENDIF}{$ENDIF}
  142. Classes
  143. { you can add units after this };
  144.  
  145. Var
  146. S: string;
  147. S1,S2: string[50];
  148. inp,outp: text;
  149. i,l: integer;
  150.  
  151. Begin
  152. assignfile(inp,'input.txt');
  153. reset(inp);
  154. assignfile(outp,'output.txt');
  155. rewrite(outp);
  156. readln(inp,S);
  157. readln(inp,S1);
  158. readln(inp,S2);
  159. l:=length(S1);
  160. if not(pos(s1,s2)=0)or(s1='') then
  161. write(outp,'-1')
  162. else begin
  163. i:=pos(S1,S);
  164. while not(i=0) do
  165. begin
  166. delete(S,i,l);
  167. insert(S2,S,i);
  168. i:=pos(S1,S);
  169. end;
  170. write(outp,S);
  171. end;
  172. closefile(outp);
  173. closefile(inp);
  174. end.
  175. end.
  176.  
  177. 2
  178. program project1;
  179.  
  180. {$mode objfpc}{$H+}
  181.  
  182. uses
  183. {$IFDEF UNIX}{$IFDEF UseCThreads}
  184. cthreads,
  185. {$ENDIF}{$ENDIF}
  186. Classes
  187. { you can add units after this };
  188.  
  189. Var
  190. S: array[1..1000000] of char;
  191. inp,outp: text;
  192. k,i,j,n,l,p: longint;
  193. c: char;
  194. flag1: boolean;
  195.  
  196. Begin
  197. assignfile(inp,'input.txt');
  198. //rewrite(inp);
  199. //writeln(inp,3);
  200. //writeln(inp,'A 10 20');
  201. //writeln(inp,'B 11 13');
  202. //writeln(inp,'Z 5 13');
  203. reset(inp);
  204. assignfile(outp,'output.txt');
  205. rewrite(outp);
  206. readln(inp,n);
  207. for k:=1 to 1000000 do s[k]:='Z';
  208. for k:=1 to n do begin
  209. readln(inp,c,i,j);
  210. for l:=i to j do s[l]:=c;
  211. end;
  212. l:=0;
  213. for c:='A' to 'Z' do begin
  214. flag1:=false;
  215. k:=0;
  216. repeat
  217. inc(k);
  218. if s[k]=c then flag1:=true;
  219. until (k=1000000)or(flag1);
  220. if flag1 then begin
  221. //write(c);
  222. inc(l);
  223. end;
  224. end;
  225. write(outp,l);
  226. write(l);
  227. closefile(outp);
  228. closefile(inp);
  229. end.
  230. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement