PAT Basic Level (1026~1030)

PAT 1026 程序运行时间

链接::http://www.patest.cn/contests/pat-b-practise/1026

代码:

#include
#include
#include
#include
#include
using namespace std;
int main()
{
    int a,b,c,d,f,g;
    scanf("%d%d",&a,&b);
    c=b-a;
    if(c/10%10>=5)
        c=c/100+1;
    else
        c=c/100;
    d=c/3600;
    f=c%3600/60;
    g=c%60;
    if(d<10)
        printf("0%d:",d);
    else
        printf("%d:",d);
    if(f<10)
        printf("0%d:",f);
    else
        printf("%d:",f);
    if(g<10)
        printf("0%d",g);
    else
        printf("%d",g);
    return 0;
}


PAT 1027 打印沙漏

链接:http://www.patest.cn/contests/pat-b-practise/1027

代码:

#include
#include
#include
#include
#include
using namespace std;
int main()
{
    char c;
    int n,m,high=0,width,r=0;
    scanf("%d %c",&n,&c);
    if(n<7)
    {
        printf("%c\n%d\n",c,n-1);
        return 0;
    }
    m=n;
    for(int i=1;;++high,i+=2)
    {
        if(i==1)
        {
            width=i;
            m-=width;
        }
        else
        {
            width=i;
            m-=(width*2);
        }
        if(m<(i+2)*2)
        {
            ++high;
            r=m;
            break;
        }
    }
    //printf("%d %d\n",width,high);
    for(int i=0;i


PAT 1028 人口普查

链接:http://www.patest.cn/contests/pat-b-practise/1028

代码:注意符合条件的人数可能为0

#include
#include
#include
#include
#include
using namespace std;
struct person
{
    int y,m,d;
    string name;
} p,oldest,youngest;
int st,en;
int cal(struct person tmp)
{
    return (tmp.y-1814)*365+tmp.m*30+tmp.d;
}
bool check()
{
    if(cal(p)en) return false;
    if(cal(p)>=cal(youngest))
    {
        youngest.name=p.name;
        youngest.y=p.y;
        youngest.m=p.m;
        youngest.d=p.d;
    }
    if(cal(p)<=cal(oldest))
    {
        oldest.name=p.name;
        oldest.y=p.y;
        oldest.m=p.m;
        oldest.d=p.d;
    }
    return true;
}
int main()
{
    int n,countx=0;
    char c[10];
    scanf("%d",&n);
    youngest.y=1814;
    youngest.m=9;
    youngest.d=6;
    oldest.y=2014;
    oldest.m=9;
    oldest.d=6;
    st=9*30+6;
    en=200*365+9*30+6;
    for(int i=0; i


PAT 1029 旧键盘

链接:http://www.patest.cn/contests/pat-b-practise/1029

代码:

#include
#include
#include
#include
#include
#include
using namespace std;
set charSet;
int main()
{
    bool flag;
    char s1[100],s2[100];
    scanf("%s%s",s1,s2);
    //printf("%s\n%s\n",s1,s2);
    int len1=strlen(s1);
    int len2=strlen(s2);
    for(int i=0,j=0; i



PAT 1030 完美数列

链接:http://www.patest.cn/contests/pat-b-practise/1030

代码:

#include
#include
#include
#include
#include
#include
using namespace std;
double v[100005];
int main()
{
    int n,maxx=0;
    double p;
    scanf("%d%lf",&n,&p);
    for(int i=0;imaxx)
                maxx =j-i+1;
        }
    printf("%d\n",maxx);
    return 0;
}





你可能感兴趣的:(PAT)