为什么我这个程序在比赛测的是一百分,到这里只有90分

Var
     f:array[1..12]of integer=((31),(28),(31),(30),(31),(30),(31),(31),(30),(31),(30),(31));
     i,d1,d2,dy1,dy2,ri1,ri2,num:longint;
     s,t:string;

Function pd(x:longint):boolean;
Var
     ri,yue:longint;
     rn:boolean;
Begin
     ri:=x div 1000+(x div 100 mod 10)*10;
     yue:=(x mod 10*10)+(x div 10 mod 10);
     if (x mod 4=0) and (x mod 100<>0) or (x mod 400=0) then
       rn:=true;
     if (x=d1) then
       if yue<dy1 then
         exit(false)
       else
         if ri<ri1 then
           exit(false);
     if x=d2 then
       if yue>dy2 then
         exit(false)
       else
         if ri>ri2 then
           exit(false);
     if (yue>=1) and (yue<=12) then
     begin
       if yue=2 then
       begin
         if rn then
           if (ri>=1) and (ri<=29) then
             exit(true)
           else
             if (ri>=1) and (ri<=28) then
               exit(true);
       end
       else
         if (ri>=1) and (ri<=f[yue]) then
           exit(true);
     end;
     exit(false);
End;

Begin
     readln(s);
     readln(t);
     for i:=1 to 4 do
     begin
       d1:=d1*10+(ord(s[i])-48);
       d2:=d2*10+(ord(t[i])-48);
     end;
     dy1:=(ord(s[5])-48)*10+(ord(s[6])-48);
     dy2:=(ord(t[5])-48)*10+(ord(t[6])-48);
     ri1:=(ord(s[7])-48)*10+(ord(s[8])-48);
     ri2:=(ord(t[7])-48)*10+(ord(t[8])-48);
     num:=0;
     for i:=d1 to d2 do
       if pd(i) then
         inc(num);
     writeln(num);
     readln;
End.

求解

4 条评论

  • @ 2017-08-16 21:12:51

    莫非vijos数据比NOIP都强?!

  • @ 2017-08-15 18:29:18

    我也是啊,第七个点错了

  • @ 2017-02-18 17:01:27

    #include <iostream>
    #include <string>
    using namespace std;
    int get(string s,bool x)
    {
    if(x==true)
    return (s[0]-48)*1000+(s[1]-48)*100+(s[2]-48)*10+(s[3]-48);
    else
    return (s[7]-48)*1000+(s[6]-48)*100+(s[5]-48)*10+(s[4]-48);
    }
    void change(int x,int a[])
    {
    int i,xx=x;
    for(i=0;i<4;i++)
    a[i]=xx%10,xx/=10;
    }
    bool judge(int a[],int year)
    {
    int month=a[0]*10+a[1],day=a[2]*10+a[3];
    if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
    {
    if(day<=31)
    {
    return true;
    }
    }
    if(month==4||month==6||month==9||month==11)
    {
    if(day<=30)
    {
    return true;
    }
    }
    if(month==2)
    {
    if(year%4==0&&year%100!=0||year%400==0)
    {
    if(day<=29)
    {
    return true;
    }
    }
    else
    {
    if(day<=28)
    {
    return true;
    }
    }
    }
    return false;
    }
    int main ()
    {
    string start,end;
    cin>>start>>end;
    int s=get(start,true),e=get(end,true),a[4],sum=0;
    if(get(start,true)<get(start,false))
    s++;
    if(get(end,true)<get(end,false))
    e--;
    while(s<=e)
    {
    change(s,a);
    if(judge(a,s)==true)
    sum++;
    s++;
    }
    cout<<sum;
    return 0;
    }
    不用枚举就行了
    测试数据 #0: Accepted, time = 0 ms, mem = 732 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 736 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 736 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 732 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 732 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 732 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 736 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 736 KiB, score = 10
    测试数据 #8: Accepted, time = 0 ms, mem = 732 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 732 KiB, score = 10
    Accepted, time = 0 ms, mem = 736 KiB, score = 100

  • @ 2017-02-18 17:01:26

    #include <iostream>
    #include <string>
    using namespace std;
    int get(string s,bool x)
    {
    if(x==true)
    return (s[0]-48)*1000+(s[1]-48)*100+(s[2]-48)*10+(s[3]-48);
    else
    return (s[7]-48)*1000+(s[6]-48)*100+(s[5]-48)*10+(s[4]-48);
    }
    void change(int x,int a[])
    {
    int i,xx=x;
    for(i=0;i<4;i++)
    a[i]=xx%10,xx/=10;
    }
    bool judge(int a[],int year)
    {
    int month=a[0]*10+a[1],day=a[2]*10+a[3];
    if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
    {
    if(day<=31)
    {
    return true;
    }
    }
    if(month==4||month==6||month==9||month==11)
    {
    if(day<=30)
    {
    return true;
    }
    }
    if(month==2)
    {
    if(year%4==0&&year%100!=0||year%400==0)
    {
    if(day<=29)
    {
    return true;
    }
    }
    else
    {
    if(day<=28)
    {
    return true;
    }
    }
    }
    return false;
    }
    int main ()
    {
    string start,end;
    cin>>start>>end;
    int s=get(start,true),e=get(end,true),a[4],sum=0;
    if(get(start,true)<get(start,false))
    s++;
    if(get(end,true)<get(end,false))
    e--;
    while(s<=e)
    {
    change(s,a);
    if(judge(a,s)==true)
    sum++;
    s++;
    }
    cout<<sum;
    return 0;
    }
    不用枚举就行了
    测试数据 #0: Accepted, time = 0 ms, mem = 732 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 736 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 736 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 732 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 732 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 732 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 736 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 736 KiB, score = 10
    测试数据 #8: Accepted, time = 0 ms, mem = 732 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 732 KiB, score = 10
    Accepted, time = 0 ms, mem = 736 KiB, score = 100

  • 1

信息

ID
2010
难度
4
分类
(无)
标签
递交数
1321
已通过
328
通过率
25%
被复制
22
上传者