Give a hint how to output in Pascal, please... Edited by author 02.11.2005 22:34 Instead of the 'example', the author of the task should have described the output format more precisly. I settled all the questions after having studied sample in/outputs and got AC immediately. Sample In/Outputs are an essential part of the situation, so I claim that output format is precisly specified in this problem. BTW, Mapping (D,M,Y) -> dayOfTheWeek was even harder for me, then following the output style. Can somebody tell smth new abot format of output. Or better about my program const dnimes:array[1..12] of longint=(31,28,31,30,31,30,31,31,30,31,30,31); var max,kol,den,perdeny,i,j,d,m,y:longint; a:array[1..7,1..33] of char; r:real; function koldnye(ye:longint):longint; begin if ye mod 400=0 then koldnye:=366 else if ye mod 100=0 then koldnye:=365 else if ye mod 4=0 then koldnye:=366 else koldnye:=365; end; function koldnmes(ye,mes:longint):longint; var h:longint; begin if mes<>2 then koldnmes:=dnimes[mes] else if ye mod 400=0 then koldnmes:=dnimes[mes]+1 else if ye mod 100=0 then koldnmes:=dnimes[mes] else if ye mod 4=0 then koldnmes:=dnimes[mes]+1 else koldnmes:=dnimes[mes]; end; begin assign(output,'out.txt');rewrite(output); read(d); read(m); read(y); for i:=1 to 7 do for j:=4 to 33 do a[i,j]:=' '; a[1,1]:='m';a[1,2]:='o';a[1,3]:='n'; a[2,1]:='t';a[2,2]:='u';a[2,3]:='e'; a[3,1]:='w';a[3,2]:='e';a[3,3]:='d'; a[4,1]:='t';a[4,2]:='h';a[4,3]:='u'; a[5,1]:='f';a[5,2]:='r';a[5,3]:='i'; a[6,1]:='s';a[6,2]:='a';a[6,3]:='t'; a[7,1]:='s';a[7,2]:='u';a[7,3]:='n'; perdeny:=6; if y>=2005 then for i:=2005 to y-1 do perdeny:=(perdeny+koldnye(i)-1) mod 7+1 else for i:=2004 downto y do perdeny:=(perdeny+371-koldnye(i)-1) mod 7+1; for i:=1 to m-1 do perdeny:=(perdeny-1+dnimes[i]) mod 7+1; den:=perdeny;kol:=1; for i:=1 to koldnmes(y,m) do begin if i=d then {if i>=10 then} begin a[den,3+5*kol]:=']'; a[den,5*kol]:='['; end; { else begin a[den,3+5*kol]:=']'; a[den,1+5*kol]:='['; end;} if i<=9 then begin a[den,2+5*kol]:=chr(i+ord('0'));; if den=7 then begin inc(kol);den:=1;end else den:=den+1; end else begin a[den,2+5*kol]:=chr(i mod 10+ord('0')); a[den,1+5*kol]:=chr(i div 10+ord('0')); if den=7 then begin inc(kol);den:=1;end else den:=den+1; end; end; {if kol=5 then r:=r/(r-r);} { max:=1; for i:=1 to 7 do begin j:=33; while a[i,j]=' ' do dec(j); for max:=1 to j do write(a[i,max]); writeln; end;} for i:=1 to 7 do begin for j:=1 to 33 do write(a[i,j]); writeln; end; end. Edited by author 12.03.2005 02:50 Edited by author 12.03.2005 02:51 i got WA again but all tests and all discuss are OK 1-is all tested ok? (such as 31 2 2003) 2-is spaces after end of line important to be or not? such as ..[31] ...30 or ..[31] ...30 3-also is it any different in 24..[31] 25...... and 24..[31] 25..... and 24..[31] 25 ???? also may you give me some other tests??? i check it by about 10 tests of discuss and also about 20time by windows calender... :((( Aidin_n7@hotmail.com ~*~*~*~*~~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~ Const NameDay : Array [0..6] of String = (('mon'),('tue'),('wed'),('thu'), ('fri'),('sat'),('sun')); Moon : Array [0..11] of byte = ((0),(3),(0),(3),(2),(3), (2),(3),(3),(2),(3),(2)); Var DD, MM, Fst, PP, MX :byte; YY, I :Integer; S :Array[0..6] of string; T :String[2]; Mark :Array[0..800] of boolean; begin ReadLn(DD,MM,YY); YY:=YY-1600; For I := 0 to 150 do Mark[4 *I] := True; For I := 0 to 8 do Mark[100*I] := False; For I := 0 To 2 do Mark[400*I] := True; fst:=(5+YY) mod 7; For I := 0 to yy-1 do If Mark[I] then fst:=(fst+1) Mod 7; If mark[YY] and (MM>2) then fst:=(fst+1) mod 7; Pp:=0; For I:=1 TO (MM-1) Do Pp:=(Pp+Moon[I]) Mod 7; fst:=(fst+Pp) mod 7; For I:=0 To 6 Do S[I]:=Nameday[I]; For I:=0 to Fst-1 Do S[I]:=S[I]+' '; For I:=Fst to 6 Do If DD=I+1-fst Then S[I]:=S[I]+' ['+' '+chr(48+I+1-fst)+']' else S[I]:=S[I]+' '+' '+chr(48+I+1-fst); MX:=28+Moon[MM]; If Mark[YY] and (Mm=2) then Inc(MX); For I:= 8-Fst To MX Do begin If I<10 Then T:=' '+chr(48+I) Else T:=chr(48+(I div 10))+chr(48+(I Mod 10)); Pp:=(I+fst-1) mod 7; S[Pp]:=S[Pp]+' '; If DD<>I-7 then S[Pp]:=S[Pp]+' '; If I=DD then S[Pp]:=S[Pp]+'['+T+']' else S[Pp]:=S[Pp]+' '+T; End; mx:=0; For I:=0 to 6 do if length(S[I])>mx then MX:=length(s[i]); For I:=0 To 6 do begin write(S[I]); if mx-1>length(s[i]) then For Pp:=1 to Mx-length(S[I]) do write(' '); writeln; end; End. > i got WA again but all tests and all discuss are OK > 1-is all tested ok? (such as 31 2 2003) > 2-is spaces after end of line important to be or not? > such as > ..[31] > ...30 > or > ..[31] > ...30 > 3-also > is it any different in > 24..[31] > 25...... > and > 24..[31] > 25..... > and > 24..[31] > 25 > ???? > also may you give me some other tests??? > i check it by about 10 tests of discuss and also > about 20time by windows calender... > :((( > Aidin_n7@hotmail.com > > ~*~*~*~*~~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~ > Const > NameDay : Array [0..6] of String = > (('mon'),('tue'),('wed'),('thu'), > ('fri'),('sat'),('sun')); > Moon : Array [0..11] of byte = > ((0),(3),(0),(3),(2),(3), > (2),(3),(3),(2),(3),(2)); > Var > DD, MM, Fst, PP, MX :byte; > YY, I :Integer; > S :Array[0..6] of string; > T :String[2]; > Mark :Array[0..800] of boolean; > > begin > ReadLn(DD,MM,YY); YY:=YY-1600; > For I := 0 to 150 do Mark[4 *I] := True; > For I := 0 to 8 do Mark[100*I] := False; > For I := 0 To 2 do Mark[400*I] := True; > > fst:=(5+YY) mod 7; > > For I := 0 to yy-1 do > If Mark[I] then > fst:=(fst+1) Mod 7; > If mark[YY] and (MM>2) then > fst:=(fst+1) mod 7; > Pp:=0; > For I:=1 TO (MM-1) Do > Pp:=(Pp+Moon[I]) Mod 7; > fst:=(fst+Pp) mod 7; > > For I:=0 To 6 Do > S[I]:=Nameday[I]; > For I:=0 to Fst-1 Do > S[I]:=S[I]+' '; > For I:=Fst to 6 Do > If DD=I+1-fst Then > S[I]:=S[I]+' ['+' '+chr(48+I+1-fst)+']' > else > S[I]:=S[I]+' '+' '+chr(48+I+1-fst); > > MX:=28+Moon[MM]; > If Mark[YY] and (Mm=2) then > Inc(MX); > For I:= 8-Fst To MX Do > begin > If I<10 Then > T:=' '+chr(48+I) > Else > T:=chr(48+(I div 10))+chr(48+(I Mod 10)); > Pp:=(I+fst-1) mod 7; > S[Pp]:=S[Pp]+' '; > If DD<>I-7 then > S[Pp]:=S[Pp]+' '; > If I=DD then > S[Pp]:=S[Pp]+'['+T+']' > else > S[Pp]:=S[Pp]+' '+T; > End; > mx:=0; > For I:=0 to 6 do > if length(S[I])>mx then > MX:=length(s[i]); > For I:=0 To 6 do > begin > write(S[I]); > if mx-1>length(s[i]) then > For Pp:=1 to Mx-length(S[I]) do > write(' '); > writeln; > end; > End. What's the point of doing easy problems like this? just do the hard ones :) speaking of which, did you get my e-mail a few days ago??? if you output 1-digit number you must write space after bracket: ..[1]-WA .[.1]-AC Who can give decision of this task (pascal) or ready samples output format how many charactors should i print? or it depend on the line you output? if the calender is like this: mon...1....8...15...22..[29] tue...2....9...16...23...30 wed...3...10...17...24...31 thu...4...11...18...25 fri...5...12...19...26 sat...6...13...20...27 sun...7...14...21...28 should I print another 5 spaces in the last 4 lines? am i right with the first line? that line has one more charactor than the second one. > how many charactors should i print? or it depend on the line you > output? > > if the calender is like this: > mon...1....8...15...22..[29] > tue...2....9...16...23...30 > wed...3...10...17...24...31 > thu...4...11...18...25 > fri...5...12...19...26 > sat...6...13...20...27 > sun...7...14...21...28 > should I print another 5 spaces in the last 4 lines? > am i right with the first line? that line has one more charactor than > the second one. > > > > how many charactors should i print? or it depend on the line you > > output? > > > > if the calender is like this: > > mon...1....8...15...22..[29] > > tue...2....9...16...23...30 > > wed...3...10...17...24...31 > > thu...4...11...18...25 > > fri...5...12...19...26 > > sat...6...13...20...27 > > sun...7...14...21...28 > > should I print another 5 spaces in the last 4 lines? > > am i right with the first line? that line has one more charactor > than > > the second one. > > > > no thanks, i have got a AC program ti; var year,day,month,week:longint; p:boolean; function rrr(year:integer):boolean; var pd:boolean; begin pd:=false; if year mod 100=0 then begin if year mod 400=0 then pd:=true; end else if year mod 4=0 then pd:=true; rrr:=pd; end; procedure yyy(num,start,ending:integer); var i:longint; begin for i:=start to ending do begin week:=week+num; if rrr(i) then week:=week+num; if week<1 then week:=week+7; if week>7 then week:=week-7; end; end; procedure clcl; var i:longint; begin if year>2002 then yyy(1,2002,year-1) else if year<2002 then yyy(-1,year,2001); for i:=1 to month-1 do begin case i of 1,3,5,7,8,10: week:=week+3; 2: if p then week:=week+1; 4,6,9,11: week:=week+2; end; if week>7 then week:=week-7; end; end; procedure scsc; var max,i,j,l,q:longint; st:string; a:array[1..7,1..35]of char; begin case month of 1,3,5,7,8,10,12: max:=31; 2: if p then max:=29 else max:=28; 4,6,9,11: max:=30; end; a[1,1]:='m'; a[1,2]:='o'; a[1,3]:='n'; a[2,1]:='t'; a[2,2]:='u'; a[2,3]:='e'; a[3,1]:='w'; a[3,2]:='e'; a[3,3]:='d'; a[4,1]:='t'; a[4,2]:='h'; a[4,3]:='u'; a[5,1]:='f'; a[5,2]:='r'; a[5,3]:='i'; a[6,1]:='s'; a[6,2]:='a'; a[6,3]:='t'; a[7,1]:='s'; a[7,2]:='u'; a[7,3]:='n'; for i:=1 to 7 do for j:=4 to 35 do a[i,j]:=' '; l:=1; q:=3; for i:=1 to max do begin str(i,st); if (7-week+i>9)and(i<10) then st:=' '+st; if l=2 then begin q:=7; l:=1; end; if l=3 then q:=2; for j:=1 to length(st) do begin a[week,(l-1)*5+3+j+q]:=st[j]; end; if day=i then begin a[week,(l-1)*5+3+q]:='['; a[week,(l-1)*5+3+q+length(st)+1]:=']'; end; week:=week+1; if week>7 then begin week:=week-7; l:=l+1; if (q=7)and(l=2) then l:=l+1; end; if i=max then begin q:=(l-1)*5+3+length(st)+q; if day=max then q:=q+1; end; end; for i:=1 to 7 do begin for j:=1 to q do write(a[i,j]); writeln; end; end; begin read(day,month,year); week:=2; p:=rrr(year); clcl; scsc; end. > program ti; > var year,day,month,week:longint; > p:boolean; > > function rrr(year:integer):boolean; > var pd:boolean; > begin > pd:=false; > if year mod 100=0 then begin if year mod 400=0 then pd:=true; > end > else if year mod 4=0 then pd:=true; > rrr:=pd; > end; > > procedure yyy(num,start,ending:integer); > var i:longint; > begin > for i:=start to ending do begin > week:=week+num; > if rrr(i) then week:=week+num; > if week<1 then week:=week+7; > if week>7 then week:=week-7; > end; > end; > > procedure clcl; > var i:longint; > begin > if year>2002 then yyy(1,2002,year-1) > else if year<2002 then yyy(-1,year,2001); > > for i:=1 to month-1 do begin > case i of > 1,3,5,7,8,10: week:=week+3; > 2: if p then week:=week+1; > 4,6,9,11: week:=week+2; > end; > if week>7 then week:=week-7; > end; > end; > > procedure scsc; > var max,i,j,l,q:longint; > st:string; > a:array[1..7,1..35]of char; > begin > case month of > 1,3,5,7,8,10,12: max:=31; > 2: if p then max:=29 > else max:=28; > 4,6,9,11: max:=30; > end; > a[1,1]:='m'; a[1,2]:='o'; a[1,3]:='n'; > a[2,1]:='t'; a[2,2]:='u'; a[2,3]:='e'; > a[3,1]:='w'; a[3,2]:='e'; a[3,3]:='d'; > a[4,1]:='t'; a[4,2]:='h'; a[4,3]:='u'; > a[5,1]:='f'; a[5,2]:='r'; a[5,3]:='i'; > a[6,1]:='s'; a[6,2]:='a'; a[6,3]:='t'; > a[7,1]:='s'; a[7,2]:='u'; a[7,3]:='n'; > for i:=1 to 7 do > for j:=4 to 35 do a[i,j]:=' '; > l:=1; > q:=3; > for i:=1 to max do begin > str(i,st); > if (7-week+i>9)and(i<10) then st:=' '+st; > if l=2 then begin q:=7; l:=1; end; > if l=3 then q:=2; > for j:=1 to length(st) do begin > a[week,(l-1)*5+3+j+q]:=st[j]; > end; > if day=i then begin > a[week,(l-1)*5+3+q]:='['; > a[week,(l-1)*5+3+q+length(st)+1]:=']'; > end; > week:=week+1; > if week>7 then begin > week:=week-7; > l:=l+1; > if (q=7)and(l=2) then l:=l+1; > end; > if i=max then begin > q:=(l-1)*5+3+length(st)+q; > if day=max then q:=q+1; > end; > end; > for i:=1 to 7 do begin > for j:=1 to q do write(a[i,j]); > writeln; > end; > end; > > begin > read(day,month,year); > week:=2; > p:=rrr(year); > clcl; > scsc; > end. Thank you very much! But I don't want to get your AC. There are two things to pay attention to: You should not use '.' character, but spaces(read carefully) and the second - if you have to highlight a one-digit number - you should do it like this: [ 6] and your program makes it [6]. Understand the difference? Anyway, here is my AC program, test yours!!! Good Luck! > There are two things to pay attention to: You should not use '.' > character, but spaces(read carefully) and the second - if you have > to highlight a one-digit number - you should do it like this: > [ 6] and your program makes it [6]. Understand the difference? > Anyway, here is my AC program, test yours!!! > Good Luck! > There are two things to pay attention to: You should not use '.' > character, but spaces(read carefully) and the second - if you have > to highlight a one-digit number - you should do it like this: > [ 6] and your program makes it [6]. Understand the difference? > Anyway, here is my AC program, test yours!!! > Good Luck! Which is right?? mon [1] 8 15 22 29 tue 2 9 16 23 30 wed 3 10 17 24 31 thu 4 11 18 25 fri 5 12 19 26 sat 6 13 20 27 sun 7 14 21 28 mon [ 1] 8 15 22 29 tue 2 9 16 23 30 wed 3 10 17 24 31 thu 4 11 18 25 fri 5 12 19 26 sat 6 13 20 27 sun 7 14 21 28 mon [ 1] 8 15 22 29 tue 2 9 16 23 30 wed 3 10 17 24 31 thu 4 11 18 25 fri 5 12 19 26 sat 6 13 20 27 sun 7 14 21 28 I suppose number 2 is correct, i.e. you print it as usual just inserting the [ character. so, correct is mon [ 1] tue 2 wed 3 etc. Good Luck! > I suppose number 2 is correct, i.e. you print it as usual just > inserting the [ character. so, correct is > mon [ 1] > tue 2 > wed 3 > > etc. > > Good Luck! program ti; var year,day,month,week:longint; p:boolean; function rrr(year:integer):boolean; var pd:boolean; begin pd:=false; if year mod 100=0 then begin if year mod 400=0 then pd:=true; end else if year mod 4=0 then pd:=true; rrr:=pd; end; procedure yyy(num,start,ending:integer); var i:longint; begin for i:=start to ending do begin week:=week+num; if rrr(i) then week:=week+num; if week<1 then week:=week+7; if week>7 then week:=week-7; end; end; procedure clcl; var i:longint; begin if year>2002 then yyy(1,2002,year-1) else if year<2002 then yyy(-1,year,2001); for i:=1 to month-1 do begin case i of 1,3,5,7,8,10: week:=week+3; 2: if p then week:=week+1; 4,6,9,11: week:=week+2; end; if week>7 then week:=week-7; end; end; procedure scsc; var max,i,j,q:longint; st:string; a:array[1..7,1..35]of char; begin case month of 1,3,5,7,8,10,12: max:=31; 2: if p then max:=29 else max:=28; 4,6,9,11: max:=30; end; a[1,1]:='m'; a[1,2]:='o'; a[1,3]:='n'; a[2,1]:='t'; a[2,2]:='u'; a[2,3]:='e'; a[3,1]:='w'; a[3,2]:='e'; a[3,3]:='d'; a[4,1]:='t'; a[4,2]:='h'; a[4,3]:='u'; a[5,1]:='f'; a[5,2]:='r'; a[5,3]:='i'; a[6,1]:='s'; a[6,2]:='a'; a[6,3]:='t'; a[7,1]:='s'; a[7,2]:='u'; a[7,3]:='n'; for i:=1 to 7 do for j:=4 to 35 do a[i,j]:=' '; q:=3; for i:=1 to max do begin str(i,st); if (i<10)and(7-week+i>9) then st:=' '+st; for j:=1 to length(st) do begin a[week,q+3+j]:=st[j]; end; if day=i then begin a[week,q+1+length(st)]:='['; a[week,q+4+length(st)]:=']'; end; week:=week+1; if week>7 then begin week:=week-7; if i>9 then q:=q+5 else q:=q+4; end; if i=max then begin if week<7 then q:=q+5; end; end; for i:=1 to 7 do begin for j:=1 to q do write(a[i,j]); writeln; end; end; begin read(day,month,year); week:=2; p:=rrr(year); clcl; scsc; end. Hey man check this: 28 11 2002 !!! :) It just does not highlight anything and writes not full solution!!! Good Luck! program xt; const name :array[1..7] of string[3]= ('mon','tue','wed','thu','fri','sat','sun'); var a :array[1..12] of integer; b,year,month,day,p,pp,i,t :integer; use :array[1..7,1..6] of integer; procedure print; var i,j:integer; begin for i:=1 to 7 do begin write(name[i]); if use[i,1]<>day then write('...') else write('.[ '); if use[i,1]<>0 then write(use[i,1]) else write('.'); if use[i,1]=day then write(']'); for j:=2 to t do begin if use[i,j]=0 then begin if use[i,j-1]<>day then write ('.....') else write ('....'); end else begin if use[i,j]<>day then begin if use[i,j-1]<>day then begin if use[i,j]<10 then write('....') else write('...'); end else if use[i,j]<10 then write('...') else write('..'); end else begin if use[i,j]<10 then write('..[ ') else write('..['); end; write(use[i,j]); if use[i,j]=day then write(']'); end; end; writeln; end; end; begin a[1]:=31; a[2]:=28; a[3]:=31; a[4]:=30; a[5]:=31; a[6]:=30; a[7]:=31; a[8]:=31; a[9]:=30; a[10]:=31; a[11]:=30; a[12]:=31; readln(day,month,year); p:=year-2002; b:=2+p; if year>2002 then begin for i:=2002 to year-1 do if ((i mod 4=0) and (i mod 100<>0)) or (i mod 400=0) then inc(b) end else for i:=year to 2002-1 do if ((i mod 4=0) and (i mod 100<>0)) or (i mod 400=0) then dec(b); b:=b mod 7; if b<=0 then b:=b+7; if ((year mod 4=0) and (year mod 100<>0)) or (year mod 400=0) then inc(a[2]); for i:=1 to month-1 do b:=(b+a[i]) mod 7; if b=0 then b:=7; fillchar(use,sizeof(use),0); t:=1; pp:=b-1; for i:=1 to a[month] do begin inc(pp); if pp>7 then begin pp:=1; inc(t); end; use[pp,t]:=i; end; print; end. If you have read the task very attentively, you must know that you must print ' ' instead '.'. Also I don't know exactly: spaces in the end of the string are necessary or not. I have got "Accepted" whithout them. I can't understand what's going on... :( Tested this thouslands of times using windows calendar, got WA :( This seems to output all correctly (dots are spaces, everything is aligned, even 1-digit numbers, date is highlighned by square brackets). Ppl plz help! =================================[Cut]============================= program WhichDayIsIt; const DaysOfWeek: array[1..7] of String[3] = ( 'mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun' ); function YearLength(Year: Integer): Integer; begin if ((Year mod 4 = 0) and (Year mod 100 <> 0)) or (Year mod 1000 = 0) then YearLength := 366 else YearLength:= 365; end; function MonthLength(Month, Year: Integer): Integer; begin case Month of 1, 3, 5, 7, 8, 10, 12: MonthLength := 31; 2: if YearLength(Year) = 365 then MonthLength := 28 else MonthLength := 29; else MonthLength := 30; end; end; function Delta(Day, Month, Year: Integer): Integer; var i, Temp: Integer; begin Temp := 0; for i := 1600 to (Year - 1) do Temp := Temp + YearLength(i); for i := 1 to (Month - 1) do Temp := Temp + MonthLength(i, Year); Temp := Temp + Day - 1; Delta := Temp; end; function DOW(Day, Month, Year: Integer): Byte; begin DOW := (Delta(Day, Month, Year) + 3) mod 7 + 1; end; function IntToStr2(i: Integer): String; var St: String; begin Str(i, St); if Length(St) < 2 then St := ' ' + St; IntToStr2 := St; end; var Day, Month, Year: Integer; i, DW: Integer; Out: array[1..7] of string; begin Read(Day, Month, Year); DW := DOW(1, Month, Year); for i := 1 to 7 do begin Out[i] := DaysOfWeek[i] + ' '; if i < DW then Out[i] := Out[i] + ' '; end; for i := 1 to MonthLength(Month, Year) do begin if i = Day then Out[(i + DW - 2) mod 7 + 1] := Out[(i + DW - 2) mod 7 + 1] + '[' + IntToStr2(i) + ']' else Out[(i + DW - 2) mod 7 + 1] := Out[(i + DW - 2) mod 7 + 1] + ' ' + IntToStr2(i) + ' '; end; for i := 1 to 7 do WriteLn(Out[i]); end. ====================================[Cut]=========================== Part of my <AC 0.02s> C++ code: // 1201 #include <iostream.h> #include <math.h> //for some calculations ;) int d,m,y; // Here are your subroutines int main() { int flg=0; int i,j,lim,k=0; int a[10][10]; char *w[]={"mon","tue","wed","thu","fri","sat","sun"}; cin>>d>>m>>y; for (i=0;i<10;i++) for (j=0;j<10;j++) a[i][j]=0; // Here you put your data in a double array for (i=0;i<7;i++) { cout<<w[i]; for (j=0;j<6;j++) if (a[i][j]) if (a[i][j]==d) { if (d>9) cout<<" ["<<d<<"] "; else cout<<" [ "<<d<<"] "; flg=j<4; } else if (flg) { if (a[i][j]>9) cout<<" "<<a[i][j]<<" "; else cout<<" "<<a[i][j]<<" "; flg=0; } else if (a[i][j]>9) cout<<" "<<a[i][j]<<" "; else cout<<" "<<a[i][j]<<" "; else cout<<" "; cout<<endl; } return 0; } We can know all where we made mistakes. #include <iostream> using namespace std; inline bool is_leap_year(int y) { return y%4==0&&(y%100!=0||y%400==0); } inline int days_per_year(int y) { if(is_leap_year(y)) return 366; else return 365; } inline int days_per_month(int m,int y) { const int days[12]={31,28,31,30,31,30,31,31,30,31,30,31}; if(m!=2) return days[m-1]; else if(is_leap_year(y)) return 29; else return 28; } int get_day_of_week(int m,int d,int y) { int day=4; int i; for(i=1600;i<y;i++) day+=days_per_year(i); for(i=1;i<m;i++) day+=days_per_month(i,y); day+=d; return day%7; } void print_calendar(int m,int d,int y) { const char* day_name[7]= {"mon","tue","wed","thu","fri","sat","sun"}; int days=days_per_month(m,y); int day_begin=1-get_day_of_week(m,1,y); for(int i=0;i<7;i++) { cout<<day_name[i]; for(int j=day_begin+i;j<=days;j+=7) if(j<1||j>days) cout<<" "; else if(j==d) { if(j<10) cout<<" [ "<<j<<"]"; else cout<<" ["<<j<<"]"; } else { if(j<10) cout<<" "<<j<<" "; else cout<<" "<<j<<" "; } cout<<endl; } } int main() { int d,m,y; cin>>d>>m>>y; print_calendar(m,d,y); return 0; } uses crt; const b:array [1..7] of string= ('mon','tue','wed','thu','fri','sat','sun'); v:array [1..12] of shortint= (31,28,31,30,31,30,31,31,30,31,30,31); var v1,data,month,year,l,t,r,n,i,j,k,x:integer; z:string; p:boolean; d:array [1..7,1..7] of string; procedure readdata; begin clrscr; readln (data,month,year); end; function leap(i:word):boolean; begin leap:=((i mod 4=0)and(i mod 100<>0))or(i mod 400=0); end; procedure first_jan_of_year; begin j:=0; for i:=1 to year do begin if leap(i) then j:=(j+2) mod 7 else j:=(j+1) mod 7; end; end; procedure find_first_day; begin for i:=1 to month-1 do if (leap(year)) and (i=2) then k:=k+29 else k:=k+v[i]; if k<>0 then begin k:=k mod 7; if k=0 then k:=7; end; j:=(j+k) mod 7; if j=0 then j:=7; if year=1600 then j:=6; end; procedure how_many_day_are_in_the_month; begin if (leap(year)) and (month=2) then x:=29 else x:=v[month]; end; procedure weeks_days; begin d[1,1]:='mon';d[2,1]:='tue'; d[3,1]:='wed';d[4,1]:='thu'; d[5,1]:='fri';d[6,1]:='sat'; d[7,1]:='sun'; end; procedure make_calendar; begin r:=0; for l:=2 to 7 do for i:=j to 7 do begin inc (r); if r>x then exit; str (r,d[i,l]); if r=data then begin if (length(d[i,l])=2) then begin d[i,l]:='['+d[i,l]+']'; d[i,l]:=' '+d[i,l]; end else begin d[i,l]:='[ '+d[i,l]+']'; if d[i,l-1]='' then begin d[i,l-1]:=' '; d[i,l]:=' '+d[i,l]; end else if (d[i,l-1]='mon')or(d[i,l-1]='tue')or(d[i,l-1] ='wed')or (d[i,l-1]='thu')or(d[i,l-1]='fri')or(d[i,l-1] ='sat')or(d[i,l-1]='sun') then d[i,l]:=' '+d[i,l] else d[i,l]:=' '+d[i,l]; end; end else begin if d[i,l-1]='' then begin d[i,l-1]:=' '; d[i,l]:=' '+d[i,l]; end else begin if length(d[i,l])=2 then begin if d[i,l-1][length(d[i,l-1])]=']' then d[i,l]:=' '+d[i,l] else d[i,l]:=' '+d[i,l] end else if L=2 then d[i,l]:=' '+d[i,l] else if (l=3)and(length(d[i,l])=1)and(d[i,l-1] [length(d[i,l-1])]=']') then d[i,l]:=' '+d[i,l] else d[i,l]:=' '+d[i,l]; end; end; if i=7 then j:=t+1; end; end; procedure print; begin for i:=1 to 7 do for j:=1 to 8 do if j>7 then writeln else write (d[i,j]); end; procedure check_calendar; begin str (x,z); l:=pos(z,d[7,6]); if (data=29)or(data=30)or(data=31) then v1:=1; if l=0 then for i:=1 to 7 do for j:=1 to 7 do if (v1=1)and(d[i,j]='') then d[i,j]:=' ' else if (d[i,j]='') then d[i,j]:=' '; if (d[1,7]=' ')or(d[1,7]=' ') then
I had correct your problem and send a E-mail to you. 31 7 2002. it is mon...1....8...15...22...29 tue...2....9...16...23...30 wed...3...10...17...24..[31] thu...4...11...18...25..... fri...5...12...19...26..... sat...6...13...20...27..... sun...7...14...21...28..... or what???????????? I've tested my program whit my windows calendar a hundred times an it works why doesnt work here? > I've tested my program whit my windows calendar a hundred times > an it works why doesnt work here? May be your programe work right but the way you print output has problem. See the discuss of this problem and you can find something useful. > > I've tested my program whit my windows calendar a hundred times > > an it works why doesnt work here? > > May be your programe work right but the way you print output has > problem. See the discuss of this problem and you can find something > useful. Thanks if eniboby knous what is error? please help me, make a kindness. const b:array [1..7] of string= ('mon','tue','wed','thu','fri','sat','sun'); v:array [1..12] of shortint= (31,28,31,30,31,30,31,31,30,31,30,31); var data,month,year,q,l,t,r,m,n,i,j,k,x:integer; pir,pir1:string; d:array [1..7,1..7] of string; procedure readdata; begin readln (data,month,year); end; function leap(i:word):boolean; begin leap:=((i mod 4=0)and(i mod 100<>0))or(i mod 400=0); end; procedure first_jan_of_year; begin j:=0; for i:=1 to year do begin if leap(i) then j:=(j+2) mod 7 else j:=(j+1) mod 7; end; end; procedure find_first_day; begin for i:=1 to month-1 do if (leap(year)) and (i=2) then k:=k+29 else k:=k+v[i]; if k<>0 then begin k:=k mod 7; if k=0 then k:=7; end; j:=(j+k) mod 7; if j=0 then j:=7; if year=1600 then j:=6; end; procedure how_many_day_are_in_the_month; begin if (leap(year)) and (month=2) then x:=29 else x:=v[month]; end; procedure weeks_days; begin d[1,1]:='mon';d[2,1]:='tue';d[3,1]:='wed'; d[4,1]:='thu';d[5,1]:='fri';d[6,1]:='sat';d[7,1]:='sun'; end; procedure make_calendar; begin r:=0; for l:=2 to 7 do for i:=j to 7 do begin inc (r); if r>x then exit; str (r,d[i,l]); if r=data then if (length(d[i,l])=2) then d[i,l]:=' [' +d[i,l]+']' else d[i,l]:=' [' +d[i,l]+']' else begin if d[i,l-1]='' then d[i,l]:=' ' +d[i,l]+' ' else begin if length(d[i,l])=2 then d[i,l]:=' ' +d[i,l]+' ' else d[i,l]:=' ' +d[i,l]+' '; end; end; if i=7 then j:=t+1; end; end; procedure change; begin for i:=1 to 7 do for j:=1 to 7 do if d[i,j]='' then d[i,j]:=' '; end; procedure print; begin for i:=1 to 7 do for j:=1 to 8 do if j>7 then writeln else write (d[i,j]); end; begin readdata; first_jan_of_year; find_first_day; how_many_day_are_in_the_month; weeks_days; make_calendar; change; print; end. > if (length(d[i,l])=2) then > d[i,l]:=' [' +d[i,l]+']' > else > d[i,l]:=' [' +d[i,l]+']' I heard you should output ' [ '+d[i,l]+']' instead of ' ['+d[i,l]+']' (justifying the day in a field of 2 digits anyway, even if it has one digit). I may be wrong. Why my program got "Wrong Answer". if you can help me, i will thank you very much!Thank you. Here is my grogram: const way:array[1..31]of string=(' 1',' 2',' 3',' 4',' 5',' 6',' 7',' 8',' 9', '10','11','12','13','14','15','16','17','1 8', '19','20','21','22','23','24','25','26','2 7', '28','29','30','31'); var a:array[0..6]of string; c,day,m,year,days,i,month:integer; begin readln(day,month,year); c:=1;fillchar(a,sizeof(a),0); a[1]:='mon';a[2]:='tue';a[3]:='wed';a[4]:='thu'; a[5]:='fri';a[6]:='sat';a[0]:='sun'; for i:=1 to month-1 do case i of 1,3,5,7,8,10,12: c:=c+31; 4,6,9,10: c:=c+30; 2: if ((year mod 4=0)and(year mod 100<>0))or(year mod 400=0) then c:=c+29 else c:=c+28; end; days:=trunc((year-1)*(1+1/4-1/100+1/400)+c) mod 7; case month of 1,3,5,7,8,10,12: m:=31; 4,6,9,10: m:=30; 2: if ((year mod 4=0)and(year mod 100<>0))or(year mod 400=0) then m:=29 else m:=28; end; for i:=1 to days-1 do a[i]:=a[i]+' '; for i:=days to 7 do begin if i-days+1=day then begin a[i mod 7]:=a[i mod 7]+' ['+way[i- days+1]+']';Continue;end; a[i mod 7]:=a[i mod 7]+' '+way[i-days+1]; end; for i:=8 to days+m-1 do begin if i-days+1=day then begin a[i mod 7]:=a[i mod 7]+' ['+way[i- days+1]+']';Continue;end; if i-days+1=day+7 then begin a[i mod 7]:=a[i mod 7]+' '+way[i- days+1];Continue;end; a[i mod 7]:=a[i mod 7]+' '+way[i-days+1]; end; for i:=1 to 7 do writeln(a[i mod 7]); end. What a bad problem...... if you know the wrong, please say clear. Thank you! Why my program got "Compilation Error". if you can help me, i will thank you very much!Thank you. Here is my grogram: const way:array[1..31]of string=(' 1',' 2',' 3',' 4',' 5',' 6',' 7',' 8',' 9', '10','11','12','13','14','15','16','17','1 8', '19','20','21','22','23','24','25','26','2 7', '28','29','30','31'); var a:array[0..6]of string; c,day,m,year,days,i,month:integer; begin readln(day,month,year); c:=1;fillchar(a,sizeof(a),0); a[1]:='mon';a[2]:='tue';a[3]:='wed';a[4]:='thu'; a[5]:='fri';a[6]:='sat';a[0]:='sun'; for i:=1 to month-1 do case i of 1,3,5,7,8,10,12: c:=c+31; 4,6,9,10: c:=c+30; 2: if ((year mod 4=0)and(year mod 100<>0))or(year mod 400=0) then c:=c+29 else c:=c+28; end; days:=trunc((year-1)*(1+1/4-1/100+1/400)+c) mod 7; case month of 1,3,5,7,8,10,12: m:=31; 4,6,9,10: m:=30; 2: if ((year mod 4=0)and(year mod 100<>0))or(year mod 400=0) then m:=29 else m:=28; end; for i:=1 to days-1 do a[i]:=a[i]+' '; for i:=days to 7 do begin if i-days+1=day then begin a[i mod 7]:=a[i mod 7]+' ['+way[i- days+1]+']';Continue;end; a[i mod 7]:=a[i mod 7]+' '+way[i-days+1]; end; for i:=8 to days+m-1 do begin if i-days+1=day then begin a[i mod 7]:=a[i mod 7]+' ['+way[i- days+1]+']';Continue;end; if i-days+1=day+7 then begin a[i mod 7]:=a[i mod 7]+' '+way[i- days+1];Continue;end; a[i mod 7]:=a[i mod 7]+' '+way[i-days+1]; end; for i:=1 to 7 do writeln(a[i mod 7]); end. There are very simle answer for your question: in CASE operator you using label 10 twice! Compiler returns 'Dublicate label' If you get WA please notice:output [ 1] not [1]! |
|