当前位置:首页 » 《关于电脑》 » 正文

山东科技大学OJ题库(上)

25 人参与  2024年11月02日 18:01  分类 : 《关于电脑》  评论

点击全文阅读


山东科技大学OJ题库

Problem 1002

#include <stdio.h>int main(){    int x,y,he,cha,ji,shang,yu,ping,san;    scanf("x = %d, y = %d",&x,&y);    he=x+y;    cha=x-y;    ji=x*y;    shang=x/y;    yu=x%y;    ping=x*x;    san=y*y*y;    printf("x + y : %d\nx - y : %d\nx * y : %d\nx / y quotient: %d, remainder: %d\nx ^ 2 : %d\ny ^ 3 : %d",he,cha,ji,shang,yu,ping,san);    return 0;}

Problem 1003

#include <stdio.h>int main(){    double a,Area,Perimeter;    scanf("%lf",&a);    Area=a*a*3.14;    Perimeter=2*a*3.14;    printf("Area: %lf\nPerimeter: %lf",Area,Perimeter);    return 0;}

Problem 1004

#include<stdio.h>int main(){    double a,b,c,d;    scanf("%lf%lf%lf",&a,&b,&c);    d=(a+b+c)/3;    printf("%.3lf",d);    return 0;}

Problem 1005

#include <stdio.h>int main(){    double x,y,a,b,c,d,e,f,g,h,i;    scanf("%lf%lf%lf",&a,&b,&c);    scanf("%lf",&x);    scanf("%lf",&y);    d=x/100*a;    e=x/100*b;    f=x/100*c;    g=y/a*100;    h=y/b*100;    i=y/c*100;    printf("%.2lf %.2lf %.2lf\n%.2lf %.2lf %.2lf",d,e,f,g,h,i);    return 0;}

Problem 1006

#include <stdio.h>#include <stdlib.h>int main(){    char a,b,c;    scanf("%c%c%c",&a,&b,&c);    printf("%03d %03o %03x\n",a,a,a);    printf("%03d %03o %03x\n",b,b,b);    printf("%03d %03o %03x",c,c,c);    return 0;}

Problem 1007

#include<stdio.h>int main(){   int a;   scanf("%d",&a);   a%2==0?printf("even"):printf("odd");   return 0;}

Problem 1008

#include <stdio.h>#include <stdlib.h>#include <math.h>int main(){    int a;    double b;    scanf("%d%lf",&a,&b);    printf("%d\n",abs(a));    printf("%g",fabs(b));    return 0;}

Problem 1009

#include <stdio.h>int main(){    double m,x,a,n,b;    scanf("%lf %lf %lf",&m,&n,&x);    if(m*x>=n)        printf("%.2lf",a=m*x*0.88);    else        printf("%.2lf",b=m*x);    return 0;}

Problem 1010

#include <stdio.h>#include <stdlib.h>int main(){    int y;    scanf("%d", &y);    if( (y % 400 == 0 && y % 100 == 0) || (y % 4 == 0 && y % 100 != 0) )         printf("Yes");    else        printf("No");    return 0;}

Problem 1012

#include <stdio.h>int main(){    int a,x,y,z;    scanf("%d",&a);    x=a/100;    y=(a-x*100)/10;    z=(a-x*100-y*10);    if(x*x*x+y*y*y+z*z*z==a)        printf("YES");    else        printf("NO");    return 0;}

Problem 1013

#include <stdio.h>int main(){    int x,a,b,c,d;    scanf("%d",&x);    a=(100-x)/20;    b=(100-x-20*a)/10;    c=(100-x-20*a-10*b)/5;    d=(100-x-20*a-10*b-5*c);    printf("$20 bills: %d\n",a);    printf("$10 bills: %d\n",b);    printf(" $5 bills: %d\n",c);    printf(" $1 bills: %d",d);    return 0;}

Problem 1014

#include <stdio.h>int main(){    int a,b,c;    scanf("(0%d)%d-%d",&a,&b,&c);    printf("0086%d%d%d",a,b,c);    return 0;}

Problem 1015

#include <stdio.h>int main(){    unsigned long long int n,a;    scanf("%llu",&n);    if(n%2==0)        a=n/2*(n+1);    else        a=(n+1)/2*n;    printf("%llu",a);    return 0;}

Problem 1018

#include <stdio.h>int main(){    int a,b,c,t;    scanf("%d %d %d",&a,&b,&c);    if(a>b){        t=a;        a=b;        b=t;    }    if(a>c){        t=c;        c=b;        b=a;        a=t;    }    if(b>c){        t=c;        c=b;        b=t;    }    printf("%d %d %d",a,b,c);    return 0;}

Problem 1019

#include <stdio.h>int main(){    int k,m,n,i;    scanf("%d%d%d",&k,&m,&n);    printf("%d",m);    i=m+1;    while(i<=k)    {      if((i%m==0||i%n==0)&&((i%m==0&&i%n==0)==0))      printf(" %d",i);      i=i+1;    }    return 0;}

Problem 1020

#include <stdio.h>int main(){    int a,b;    while(scanf("%d %d",&a,&b) != EOF)    printf("%d\n",a+b);    return 0;}

Problem 1021

#include<stdio.h>int main(){    int a,b;    int N;    scanf("%d",&N);    while(N--)    {        scanf("%d %d",&a,&b);        printf("%d\n",a+b);    }    return 0;} 

Problem 1022

#include <stdio.h>#include <string.h>#include <stdlib.h>int main(){    int a, b;    while(scanf("%d %d", &a, &b)!=EOF)    {        if(a==0&&b==0)        return 0;        else        printf("%d\n", a+b);    }}

Problem 1023

#include <stdio.h>int main(){    int a,b,sum;    scanf("%d%d",&a,&b);    printf("%d\n",a+b);    while (scanf("%d %d",&a,&b)!=EOF)    {        sum=a+b;        printf("\n%d\n",sum);    }}

Problem 1024

#include <stdio.h>int main(){    int n,a,b,i,x,y;         scanf("%d%d",&n,&b);         x=b;         y=b;         for(i=2;i<=n;i++)         {        scanf("%d",&a);                 if(a>x)                 {                     x=a;                  }                 if(a<y)                 {                         y=a;                     }             }         printf("The maximum number is %d.\nThe minimum number is %d.",x,y);         return 0; }

Problem 1025

#include <stdio.h>#include <stdlib.h>int main(){    int a;    while(scanf("%d",&a)!=EOF)    if(a>=0&&a<=100)    {        if(a>=90&&a<=100)            printf("Excellent\n");        if(a>=80&&a<90)            printf("Good\n");        if(a>=70&&a<80)            printf("Average\n");        if(a>=60&&a<70)            printf("Pass\n");        if(a>=0&&a<60)            printf("Failing\n");    }    else        printf("Error\n");    return 0;}

Problem 1026

#include <stdio.h>#include <stdlib.h>int main(){    int a,b;    char c;    while(scanf("%d%c%d",&a,&c,&b)!=EOF)    {        if(a==0&&b==0&&c==' ')            exit(0);        else        {            switch(c)            {                case'+':printf("%d\n",a+b);break;                case'-':printf("%d\n",a-b);break;                case'*':printf("%d\n",a*b);break;                case'/':printf("%d\n",a/b);break;                case'%':printf("%d\n",a%b);break;                default:printf("invalid op\n");            }        }    }    return 0;}

Problem 1027

#include <stdio.h>int main(){    int m,n,i,j,k;    scanf("%d %d",&m,&n);    printf("=====\n");    for(i=n;i>=m;i--)    {  k=0;       for(j=1;j<i;j++)       if(i%j==0)       k++;       if(k==1)       printf("%d\n",i);    }    printf("=====");}

Problem 1028

#include<stdio.h>#include<string.h>int main(){    char a,b;    double c,d,e,f;    scanf("%c->%c",&a,&b);    scanf("%lf%lf%lf",&c,&d,&e);    if(a=='C'&&b=='F')    {        printf("   C  ->    F\n");        for(c;c<=d+0.01;c+=e)        {            f=32+c*9/5.0;            printf("%5.1lf -> %5.1lf\n",c,f);        }    }    else if(a=='F'&&b=='C')    {        printf("   F  ->    C\n");        for(c;c<=d+0.01;c+=e)        {            f=(c-32)*5/9;            printf("%5.1lf -> %5.1lf\n",c,f);        }    }    return 0;}

Problem 1041

#include<stdio.h>int main(){    int a,b,m,n,p;    while(scanf("%d%d",&m,&n)!=EOF)    {        if(m>=n)        {            a=m;            b=n;        }        else        {            a=n;            b=m;        }        if(b==0)            {                printf("%d %d\n",a,b);            }        if(a!=0&&b!=0)        {            while(a%b!=0)            {                p=a%b;                a=b;                b=p;            }            if(a%b==0)                printf("%d %d\n",b,m/b*n);        }    }   return 0;}

Problem 1042

#include <stdio.h>int main(){    int N,i,a,sum;         while(scanf("%d",&N)!=EOF)         {             sum=0;                 for(i=1;i<=N;i++)                 {            scanf("%d",&a);                         sum=sum+a;        }                 printf("%d\n",sum);                 }     return 0;}

Problem 1043

#include <stdio.h>int main(){    int M,N,j,i,a,sum;         scanf("%d",&M);         for(j=1;j<=M;j++)         {           scanf("%d",&N);                 sum=0;                 for(i=1;i<=N;i++)                 {            scanf("%d",&a);                         sum=sum+a;        }                 printf("%d\n",sum);                 }     return 0;}

Problem 1044

#include <stdio.h>int main(){    int N,i,a,sum;         while(scanf("%d",&N)&&N!=0)         {            sum=0;                 for(i=1;i<=N;i++)                 {            scanf("%d",&a);                         sum=sum+a;        }                 printf("%d\n",sum);                 }     return 0;}

Problem 1045

#include <stdio.h>int main(){    int M,N,j,i,a,sum;         scanf("%d",&M);         for(j=1;j<=M;j++)         {           scanf("%d",&N);                 sum=0;                 for(i=1;i<=N;i++)                 {            scanf("%d",&a);                         sum=sum+a;        }                 printf("%d\n\n",sum);                 }     return 0;}

Problem 1046

#include <stdio.h>int main (){    int a,b,c,d,m,n;    scanf("COCK,HEN,CHICK,MONEY,CHICKS");    while(scanf("%d,%d,%d/%d,%d,%d",&a,&b,&c,&d,&m,&n)!=EOF)    {        int judge=1;        int x,y,z;        int first=1;        for(x=0;x<=m/a;x++)        {            y=(m*d-c*n-(a*d-c)*x)/(b*d-c);            z=(m*d-b*d*n-(a-b)*d*x)/(c-b*d);            if( x+y+z==n && (a*x*d+b*y*d+c*z)==m*d && y>=0 &&z>=0)            {                if(first) {printf("COCKS,HENS,CHICKS\n");first=0;}                printf("%d,%d,%d\n",x,y,z);                judge=0;            }        }        if(!judge) printf("\n");        if(judge) printf("Cannot buy!\n\n");    }}

Problem 1047

#include<stdio.h>int main(){    unsigned long long k;    while(scanf("%llu",&k)!=EOF)    {        if(k>1)        {            printf("%llu471\n",k-1);        }        else        {            printf("471\n");        }    }    return 0;}

Problem 1050

#include <stdio.h>#include <string.h>int main(){    int a[1001]={0};    int b[1001]={0};    int c[1001]={0};//初始化数组     int i,j,k=0;    int d;    int s;    while(scanf("%d",&d)!=EOF)    {        k++;        if(k%2!=0)//讨论奇偶数情况的赋值        {            for(i=0; i<d; i++)                scanf("%d",&a[i]);        }        else        {            for(j=0; j<d; j++)                scanf("%d",&b[j]);        }        if(k%2==0)//两次一输出        {            if(i>j)            {                for(s=0; s<i; s++)                {                    c[s]=a[s]+b[s];                }                for(s=0; s<i; s++)                {                    if(s==0)                    printf("%d",c[0]);                    else                    printf(" %d",c[s]);                }                printf("\n");                memset(a,0,sizeof(a));                memset(b,0,sizeof(b));                memset(c,0,sizeof(c));//输出一次清空一次            }            else            {                for(s=0; s<j; s++)                {                    c[s]=a[s]+b[s];                }                for(s=0; s<j; s++)                {                    if(s==0)                    printf("%d",c[0]);                    else                    printf(" %d",c[s]);                }                printf("\n");                memset(a,0,sizeof(a));                memset(b,0,sizeof(b));                memset(c,0,sizeof(c));            }        }    }    if(d!=0&&k%2==1)//讨论奇数次输出 最后一次输出的情况        for(s=0; s<i; s++)        {            if(s==0)                printf("%d",a[s]);            else                printf(" %d",a[s]);        }        printf("\n");    if(d==0&&k%2==1)        printf("\n");}

Problem 1051

#include <stdio.h>#include <string.h>//Cint main(){    int a[1002]={0};    int b[1002]={0};    int c[1002]={0};    int i,j,k=0;    int d;    int z;    int s;    scanf("%d",&d);    for(z=1;z<=d;z++)    {        k++;        if(k%2!=0)        {            for(i=0;;i++)//赋值数组直到0时break               {                scanf("%d",&a[i]);                if(a[i]==0)                {                a[i]='\0';                break;                }               }        }        else        {                for(j=0;; j++)//同上                {scanf("%d",&b[j]);                if(b[j]==0)                {b[j]='\0';                break;                }                }         }        if(k%2==0)//两次输出一次        {            if(i>j)            {                for(s=0; s<i; s++)                {                    c[s]=a[s]+b[s];                }                for(s=0; s<i; s++)                {                    if(s==0)                    printf("%d",c[0]);                    else                    printf(" %d",c[s]);                }                printf("\n");                memset(a,0,sizeof(a));                memset(b,0,sizeof(b));                memset(c,0,sizeof(c));            }            else            {                for(s=0; s<j; s++)                {                    c[s]=a[s]+b[s];                }                for(s=0; s<j; s++)                {                    if(s==0)                    printf("%d",c[0]);                    else                    printf(" %d",c[s]);                }                printf("\n");                memset(a,0,sizeof(a));                memset(b,0,sizeof(b));                memset(c,0,sizeof(c));            }        }     if(k==d&&d%2==1)        {        for(s=0; s<i; s++)        {            if(s==0)                printf("%d",a[s]);            else                printf(" %d",a[s]);        }        printf("\n");        }    if(k==d&&d%2==1&&strlen(a)==0)//这种strlen的用法应该不对 但莫名其妙就过了 懵逼        {printf("\n");}    }}

Problem 1052

#include <stdio.h>#include <string.h>int main() {    int q,i,t,m,n,x;    int a[1001]= {0};    int b[1001]= {0};    scanf("%d",&n);    for(q=1; q<=n; q++)    {        if(q%2!=0)        {            scanf("%d",&t);            for(i=0; i<t; i++)                scanf("%d",&a[i]);            if(q!=1)            {                if(t>m)                    x=t;                else                    x=m;                if(x==0)                    printf("\n");                else                {                    for(i=0; i<x; i++)                    {                        if(i==0)                            printf("%d",a[i]+b[i]);                        else                            printf(" %d",a[i]+b[i]);                    }                    printf("\n");                    memset(b,0,sizeof(b));                }            }            if(q==n)            {                for(i=0; i<t; i++)                {                    if(i==0)                        printf("%d",a[i]);                    else                        printf(" %d",a[i]);                }                printf("\n");            }        }        else        {            scanf("%d",&m);            for(i=0; i<m; i++)                scanf("%d",&b[i]);            if(t>m)                x=t;            else                x=m;            if(x==0)            {                printf("\n");            } else {                for(i=0; i<x; i++) {                    if(i==0)                    {                        printf("%d",a[i]+b[i]);                    } else                    {                        printf(" %d",a[i]+b[i]);                    }                }                printf("\n");                memset(a,0,sizeof(a));            }            if(q==n)                {                for(i=0; i<m; i++)                {                    if(i==0)                    {                        printf("%d",b[i]);                    } else {                        printf(" %d",b[i]);                    }                }                printf("\n");            }        }    }    return 0;}

Problem 1053

#include <stdio.h>#include <stdlib.h>int main(){    int i,j,n,m,M,k;    int a[101][101];    scanf("%d",&M);    for(k=0;k<M;k++)    {        scanf("%d%d",&m,&n);        for(i=0;i<m;i++)        {            for (j=0;j<n;j++)            {                scanf("%d",&a[i][j]);            }        }        for (j=0;j<n;j++)        {            for (i=0;i<m;i++)            {                if(i==0)                {                    printf("%d",a[i][j]);                }                else                {                    printf(" %d",a[i][j]);                }            }            printf("\n");        }        printf("\n");    }    return 0;}

Problem 1054

#include<stdio.h>#include<string.h>int main(){    int arr1[105][105],arr2[105][105];    int x,y;    while(scanf("%d%d",&x,&y)!=EOF&&x!=0&&y!=0)    {        int i,j,m, n;        for(i=0; i<x; i++)            for(j=0; j<y; j++)                scanf("%d",&arr1[i][j]);        scanf("%d%d",&m,&n);        for(i=0; i<m; i++)            for(j=0; j<n; j++)                scanf("%d",&arr2[i][j]);        if(m==0&&n==0)            break;        else if(m==x&&n==y)        {            for(i=0; i<x; i++)            {                for(j=0; j<y; j++)                {                    if(j==0)                        printf("%d",arr1[i][j]+arr2[i][j]);                    else                        printf(" %d",arr1[i][j]+arr2[i][j]);                }                printf("\n");            }            printf("\n");        }        else            printf("Not satisfied the definition of matrix addition!\n\n");    }}

Problem 1060

#include<stdio.h>#include<stdlib.h>#include<string.h>int main(){    char min[10000]="", max[10000]="",a[1002], b[1002];    int i, lmin, lmax, lena, lenb;    while(scanf("%s",a)!= EOF)    {        i=0;        lena=strlen(a);        while(a[i]=='0'&&i<lena-1)            i++;        strcpy(b,a+i);        lmax=strlen(max);        lmin=strlen(min);        lenb=strlen(b);        if(lenb>lmax||(lenb==lmax&&strcmp(b,max)>0))            strcpy(max,b);        if(strcmp(min,"")==0||lenb<lmin||(lenb==lmin&&strcpy(b,min)<0))            strcpy(min,b);    }    printf("The maximum value is : %s\n",max);    printf("The minimum value is : %s\n",min);    return 0;}

Problem 1061

#include<stdio.h>#include<string.h>int main(){    char ch[1001];    while(gets(ch)!=NULL)    {        //puts(ch);        char cha[1001]={0};        int lenth=strlen(ch);int j=0;        for(int i=0;i<=lenth-1;i++)//转存        {            if(ch[i]>='0'&&ch[i]<='9')                {cha[j]=ch[i];j++;}            if(ch[i]>='a'&&ch[i]<='z')            {cha[j]=ch[i];j++;}            if(ch[i]>='A'&&ch[i]<='Z')                {cha[j]=ch[i]+32;j++;}        }        int chang=strlen(cha);        int flag=0;        for(int i=0;i<=chang/2-1;i++)        {            if(cha[i]!=cha[chang-1-i])                flag++;        }        if(flag!=0)            printf("No.\n");        else            printf("Yes.\n");    }    return 0;}

Problem 1062

#include<stdio.h>#include<string.h>#include<stdlib.h>int main(){    int m,n,i,j,k,num,len,x,l;    char s[10005];    scanf("%d",&m);    for(i=1;i<=m;i++)    {        scanf("%d%d",&n,&k);        getchar();//必不可少...        for(j=1;j<=n;j++)        {            gets(s);            num=0;            len=strlen(s);            for(l=0;l<len;l++)                if((s[l]>=65&&s[l]<=90)||(s[l]>=97&&s[l]<=122))                {                    num++;                    if(s[l]>=97&&s[l]<=122)                        s[l]=s[l]-32;                    if(s[l]+k>90)                        s[l]=s[l]+k-26;                    else if(s[l]+k<65)                        s[l]=s[l]+k+26;                    else                        s[l]=s[l]+k;                }            printf("%d ",num);            for(x=0;x<len;x++)                if(s[x]>=65&&s[x]<=90)                printf("%c",s[x]);            printf("\n");        }        printf("\n");    }   }

Problem 1068

#include <stdio.h>#include <stdlib.h>#include <string.h>char zero[] = "323101303101323",one[] = "303301303301303",two[] = "323301323103323",three[] = "323301323301323",four[] = "303101323301303",five[] = "323103323301323",six[] = "323103323101323",seven[] = "323301303301303",eight[] = "323101323101323",nine[] = "323101323301323";void p_rint(int n,char de[],int k,int jj){    int i,j,p = k*3,pd = 1;    for(i = 0; i < 3; i++)    {        for(j = 0; j < n; j++)        {            if(de[p] == '0')            {                printf(" ");                pd = 1;            }            if(de[p] == '2')            {                printf("-");                pd = 1;            }            if(de[p] == '1' && pd == 1)            {                printf("|");                pd = 0;            }        }        if(de[p] == '3')            printf(" ");        p++;    }    if(jj == 1)        printf(" "); }int main(){    int n,tp = 0,jj;    char w[9];    memset(w,0,sizeof(w));    while(~scanf("%d%s",&n,w))    {        if(n == 0)            return 0;        if(tp++ != 0)            printf("\n");        int i,j,pd = 0,t,g;        for(i = 0; i < 5; i++)        {            if(i%2 != 0)                t = n;            else                t = 1;            for(g = 0; g < t; g++)            {                jj = 1;                for(j = 0; j < strlen(w); j++)                {                    if(j+1 == strlen(w))                        jj = 0;                    if(w[j] == '0')                        p_rint(n,zero,i,jj);                    if(w[j] == '1')                        p_rint(n,one,i,jj);                    if(w[j] == '2')                        p_rint(n,two,i,jj);                    if(w[j] == '3')                        p_rint(n,three,i,jj);                    if(w[j] == '4')                        p_rint(n,four,i,jj);                    if(w[j] == '5')                        p_rint(n,five,i,jj);                    if(w[j] == '6')                        p_rint(n,six,i,jj);                    if(w[j] == '7')                        p_rint(n,seven,i,jj);                    if(w[j] == '8')                        p_rint(n,eight,i,jj);                    if(w[j] == '9')                        p_rint(n,nine,i,jj);                }                printf("\n");            }        }        memset(w,0,sizeof(w));    }    return 0;}

Problem 1079

#include <stdio.h>int main(){    int a,b,c,i,n;    scanf("%d\n",&n);    for(i=1;i<=n;i++)    {        scanf("%d%d%d",&a,&b,&c);        if((a+b)>c&&(a+c)>b&&(b+c)>a)            printf("YES\n");        else            printf("NO\n");    }    return 0;}

Problem 1088

#include <stdio.h>int main(){    int a;    scanf("%d",&a);    if(a==0)        printf("0");    if(a>0&&a<=9)        printf("%d",a%100);    if(a>=10)        printf("%02d",a%100);    if(a<0&&a>=-9)        printf("%d",(-a)%100);    if(a<=-10)        printf("%02d",(-a)%100);    return 0;}

Problem 1089

#include <stdio.h>#include <stdlib.h>int main(){    int a,b;    scanf("%d/%d",&a,&b);    printf("%.2lf",(double)a/b);    return 0;}

Problem 1092

#include<stdio.h>#include<string.h>int main(){    int n,i;    char str0[101],a[101];    scanf("%s",&str0);    n=strlen(str0);    strcpy(a,str0);    for(i=n-1;i>=0;i--)    {        printf("%c",a[i]);    }    return 0;}

Problem 1093

#include<stdio.h>#include<string.h>#include<stdlib.h> int main(){         char s[20];    scanf("%s",s);         int num=0;    char ss[20];    while(scanf("%s",ss)!=EOF){        if(num<5&&strcmp(ss,s)==0){            printf("Welcome!\n");            break;        }        else if(num<5&&strcmp(ss,s)!=0){            printf("Wrong!\n");        }        else{            printf("Out of limited!\n");        }        num++;    }    return 0;} 

Problem 1094

#include <stdio.h>#include <string.h>#include <ctype.h>int main(){    int i,n,j;    char c[105];    while(gets(c))    {        j=0;        n=strlen(c);        for(i=n-1;isspace(c[i]);i--);        c[i+1]=0;        for(i=0;isspace(c[i]);i++);            printf("%s\n",&c[i]);        if(strcmp(&c[i],"END")==0)            break;    }    return 0;}

Problem 1097

#include <stdio.h>int main(){    int a,b,c;    while(scanf("%d %d %d",&a,&b,&c)!=EOF)    {        if(a+b>c&&a+c>b&&b+c>a)            {                 if(a==b&&b==c)                      printf("a equileteral triangle\n");                 else if(a==b||b==c||a==c)                      printf("a isosceles triangle\n");                 else if(a*a==b*b+c*c||b*b==a*a+c*c||c*c==a*a+b*b)                      printf("a right triangle\n");                 else                      printf("a triangle\n");            }        else if(a==0||b==0||c==0)            break;    else        printf("not a triangle\n");    }    return 0;}

Problem 1100

#include <stdio.h>#include <stdlib.h>int main(){    int month, i, j;    scanf("%d", &month);printf("Sun Mon Tue Wen Thu Fri Sat\n");    if(month >= 7)        month -= 7;        for(i = 1; i <= month; i++)            printf("    ");        for(i = month + 1, j = 1; j <= 30; i++, j++)        {            printf("%3d", j);            if(i % 7 == 0 && j != 30)                printf("\n");            if(i % 7 != 0 && j != 30)                printf(" ");        }    return 0;}

Problem 1101

#include <stdio.h>#include <string.h>int main(){    int n,year,month,day,i,sum,j;    scanf("%d",&n);    for(i=1;i<=n;i++)    {        int a[15]={0,31,28,31,30,31,30,31,31,30,31,30,31};        sum=0;        scanf("%d-%d-%d",&year,&month,&day);        if((year%4==0&&year%100!=0)||(year%400==0))            a[2]=29;        if((day>0&&day<=a[month])&&(month>0&&month<=12))        {            for(j=1;j<month;j++)            {                sum+=a[j];            }            sum+=day;            printf("%d\n",sum);        }        else            printf("error date!\n");    }    return 0;}

Problem 1107

#include<stdio.h>#define SWAP(t,a,b) t = a;a = b; b = t;int int_swap(int *x1, int *y1){    int t;    t = *x1;    *x1 = *y1;    *y1 = t;}double dbl_swap(double *x2, double *y2){    double t;    t = *x2;    *x2 = *y2;    *y2 = t;}int main(){    int x1, y1, t1;    double x2, y2, t2;    scanf("%d %d", &x1, &y1);    int_swap(&x1, &y1);    printf("%d %d\n", x1, y1);    scanf("%d %d", &x1, &y1);    SWAP(t1, x1, y1);    printf("%d %d\n", x1, y1);    scanf("%lf %lf", &x2, &y2);    dbl_swap(&x2, &y2);    printf("%lg %lg\n", x2, y2);    scanf("%lf %lf", &x2, &y2);    SWAP(t2, x2, y2);    printf("%lg %lg\n", x2, y2);}

Problem 1133

#include<stdio.h>#include<string.h>#include<stdlib.h>#define MAX_STR_LEN 11int strToInt(char str[]){    int i,j,k=1,n=0;    int a[11];    if(strlen(str)==0)        return -1;    else    {        for(i=0;str[i]>=48&&str[i]<=57;i++);        if(i==0)            return 0;        else        {            for(j=i-1;j>=0;j--)            {                n+=(str[j]-48)*k;                k*=10;            }            return n;        }    }}int main(){    char s[MAX_STR_LEN];    while(gets(s) != NULL)        printf("%d\n", strToInt(s));    return 0;}

Problem 1134

#include<stdio.h>#include<string.h>#include<stdlib.h>#define MAX_STR_LEN 11int strToInt(char str[]){    int i,j,k=1,n=0,flag=0;;    if(strlen(str)==0)        return 0;    else    {        for(i=0;;i++)        {            if(i==0)            {                if(str[i]=='-')                continue;                else if(str[i]=='+')                continue;            }            if(str[i]<48||str[i]>57)                break;        }        if(i==0)            return 0;        if(str[0]=='-')        {            for(j=i-1;j>=1;j--)            {                n+=(str[j]-48)*k;                k*=10;            }            return -n;        }        else if(str[0]=='+')        {            for(j=i-1;j>=1;j--)            {                n+=(str[j]-48)*k;                k*=10;            }            return n;    }        else        {            for(j=i-1;j>=0;j--)            {                n+=(str[j]-48)*k;                k*=10;            }            return n;        }    }}int main(){    char s[MAX_STR_LEN];    while(gets(s) != NULL)        printf("%d\n", strToInt(s));    return 0;}

Problem 1135

#include<stdio.h>#include<string.h>#include<stdlib.h>#define MAX_STR_LEN 11int strToInt(char str[]){    int i,j,k=1,n=0,flag=0,len;    int a[11]={0};    if(strlen(str)==0)        return 0;    else    {        j=0;        for(i=0;str[i]!='\0';i++)        {            if(str[i]>=48&&str[i]<=57)                {a[j]=str[i]-48;flag=1;j++;}        }        len=j;        if(flag==0)            return 0;        if(str[0]=='-')        {            for(j=len-1;j>=0;j--)            {                n+=a[j]*k;                k*=10;            }            return -n;        }        else if(str[0]=='+')        {            for(j=len-1;j>=0;j--)            {                n+=a[j]*k;                k*=10;            }            return n;        }        else        {            for(j=len-1;j>=0;j--)            {                n+=a[j]*k;                k*=10;            }            return n;        }    }}int main(){    char s[MAX_STR_LEN];    while(gets(s) != NULL)        printf("%d\n", strToInt(s));    return 0;}

Problem 1136

#include <stdio.h>#include <string.h>#include <math.h>#include <stdlib.h>#define MAX_STR_LEN 111int TWO(char str[],int x){    int i,j=1,s=0;    for(i=x;i>=0;i--)    {        if(str[i]=='1'||str[i]=='0')        {            s+=(str[i]-48)*pow(2,j-1);            j++;        }    }    return s;}int EIGHT(char str[],int x){    int i,j=1,s=0;    for(i=x;i>=0;i--)    {        if(str[i]>='0'&&str[i]<='7')        {            s+=(str[i]-48)*pow(8,j-1);            j++;        }    }    return s;}int TEN(char str[],int x){    int j,s=0,k=1;    for(j=x;j>=0;j--)    {        s+=(str[j]-48)*k;        k=k*10;    }    return s;}int SIXTEEN(char str[],int x){    int i,j=1,s=0;    for(i=x;i>=0;i--)    {        if((str[i]>='0'&&str[i]<='9')||(str[i]>='A'&&str[i]<='F')||(str[i]>='a'&&str[i]<='f'))        {            if(str[i]>='0'&&str[i]<='9')            {                s+=(str[i]-48)*pow(16,j-1);                j++;            }            else if (str[i]>='A'&&str[i]<='F')            {                s+=(str[i]-55)*pow(16,j-1);                j++;            }            else            {                s+=(str[i]-87)*pow(16,j-1);                j++;            }        }    }    return s;}int strToInt(char str[], int base){    int n,i,j=0,m,k=1,s=0;    char hold[105];    n=strlen(str);    if(n==0)        return 0;    else    {        for(i=0;i<n;i++)        {            if(str[i]>='0'&&str[i]<='9')            {                hold[j]=str[i];                j++;            }            hold[j]='\0';        }        j--;        if(base==10)            s=TEN(hold,j);        else if(base==2)            s=TWO(hold,j);        else if(base==8)            s=EIGHT(hold,j);        else if(base==16)            s=SIXTEEN(str,n);        if(str[0]=='-')            return -s;        else            return s;    }}int main(){    int base;    char s[MAX_STR_LEN];    while( (scanf("%d:", &base) != EOF) && (gets(s) != NULL) )        printf("%d\n", strToInt(s, base));    return 0;}

Problem 1137

#include <stdio.h>#include <stdlib.h>#include <math.h>#include <string.h>#include <ctype.h>#define  MAX_STR_LEN  120double strToDouble(char str[]){    int i,j,k=0,n,p;    double l,m;    char c[15];    for(i=0,j=1;str[i]!='\0';i++)    {        if(str[i]=='.'||(str[i]>='0'&&str[i]<='9'))        {            if((str[i]>='0'&&str[i]<='9'))            {                c[j]=str[i];                j++;            }            else            {                c[j]=str[i];                k=j;                j++;                break;            }        }        c[j]='\0';    }    if(k!=0)    {        for(;str[i]!='\0';i++)        {            if(str[i]>='0'&&str[i]<='9')                {                    c[j]=str[i];                    j++;                }        }        c[j]='\0';    }    if(j==1)        return 0;    else    {        n=j-1;        l=1;        m=0;        if(k!=0)            p=k-1;        else            p=n;        for(j=p;j>=1;j--)        {            m+=(c[j]-48)*l;            l=l*10;        }        if(k!=0)        {            l=0.1;            for(j=k+1;j<=n;j++)            {                m+=(c[j]-48)*l;                l=l/10;            }        }        if(str[0]=='-')            return -m;        else            return m;    }}int main(){    char s[MAX_STR_LEN];    while(gets(s) != NULL)        printf("%lg\n", strToDouble(s));    return 0;}

Problem 1138

#include<stdio.h>#define MAX_STR_LEN 110  //注意定义宏int str_cmp(char s1[], char s2[]){    int flag;    for (int i=0; s1[i]!='\0'||s2[i]!='\0'; i++)    {        if (s1[i]==s2[i])            flag=0;        if (s1[i]>s2[i])        {            flag=s1[i]-s2[i];            return flag;        }        if (s1[i]<s2[i])        {            flag=s1[i]-s2[i];            return flag;        }    }    return 0;}int main(){    char str1[MAX_STR_LEN], str2[MAX_STR_LEN];    while( (gets(str1) != NULL) && (gets(str2) != NULL) )        printf("%d\n", str_cmp(str1, str2));    return 0;}

Problem 1139

#include <stdio.h>#define MAX_STR_LEN 101 int str_cmp(char s1[MAX_STR_LEN], char s2[MAX_STR_LEN]){    int i;    for(i=0;s1[i]!='\0'||s2[i]!='\0';i++)    {        if(s1[i]==s2[i]||(char)(s1[i]-32)==s2[i]||s1[i]==(char)(s2[i]-32)||(char)(s1[i]-32)==(char)(s2[i]-32))        {            continue;        }        if(s1[i]!=s2[i])        {            return s1[i]-s2[i];            break;        }    }} int main(){    char str1[MAX_STR_LEN], str2[MAX_STR_LEN];    while( (gets(str1) != NULL) && (gets(str2) != NULL) )        printf("%d\n", str_cmp(str1, str2));    return 0;}

Problem 1140

#include<stdio.h>#include<string.h>#define MAX_SIZE 1001int getarray(int array[]){    int i;    for(i=0;i<MAX_SIZE;i++)        {            scanf("%d",&array[i]);            if(array[i]==0)            break;        }    return array;}int insert(int array[], int key, int vol){    int i,k=0;    for(i=0;array[i]!=0;i++);    k=i;    if(k>vol-1)        return -1;    else    {        for(i=0;i<k;i++)        {            if(key==array[i])                return -2;            if(key<array[i])                return i;        }    }}int result(int flag){    if(flag==-1)        printf("The array if full!\n");    else if(flag==-2)        printf("The key is already in this array!\n");    else        printf("The key is inserted in position %d.\n",flag);}int main(){    int array[MAX_SIZE], cases, i, key;    scanf("%d", &cases);    for(i = 1; i <= cases; i++)    {        getarray(array);        scanf("%d", &key);        result(insert(array, key, MAX_SIZE - 1));    }    return 0;}

Problem 1141

#include <stdio.h>#include <string.h>#define MAX_SIZE (1000) int f=0; int getarray(int *array){    int i=0,a;    while(1)    {        scanf("%d",&a);        if(a==0) return 0;        array[i++]=a;        f=i;    }} int getkey(int *key){    int n=0,i;    scanf("%d",&n);    for(i=0;i<n;++i) scanf("%d",&key[i]);    return n;} int insert(int *a,int key,int num){    if(f==MAX_SIZE) return -2;    int i=0;    if(key>a[f-1]) i=f;    else{        for(i=0; i<f; ++i)        {            if(key==a[i]) return -1;            if(a[i]>key) break;        }    }    int k=0;    for(k=f;k>i;--k)    {        a[k]=a[k-1];    }    a[i]=key;    ++f;    return i;} int result(int flag){    if(flag==-2) puts("The array if full!");    else if(flag==-1) puts("The key is already in this array!");    else printf("The key is inserted in position %d.\n",flag); }int main(){    int array[MAX_SIZE], cases, ca, i, key[MAX_SIZE], size;    scanf("%d", &cases);    for(ca = 1; ca <= cases; ca++)    {        getarray(array);        size = getkey(key);        printf("Case %d:\n", ca);        for(i = 0; i < size; i++)            result(insert(array, key[i], MAX_SIZE - 1));    }    return 0;}

Problem 1143

#include <stdio.h>int print_graphic(int n, char c){    int i,j;     for(j=1;j<=n;j++)    {       for(i=1;i<=(n-j);i++)       {        printf(" ");       }       for(i=1;i<=2*j-1;i++)       {        printf("%c",c);       }       printf("\n");    }}int main(){    char c;    int num;    scanf("%d %c", &num, &c);    print_graphic(num, c);    return 0;}

Problem 1144

#include <stdio.h>#include <stdlib.h>#define MAX_SIZE 10000int get_array(int a[]){   int n;   scanf("%d",&n);   for(int i=0;i<n;i++)//for语句分号;顺序;<而不是<=   scanf("%d",&a[i]); //scanf &   return n;}int put_array(int a[], int n){  int i;  for(i=0;i<n;i++)    {if(i==0)     //使3 8中有逗号    printf("%d",a[i]);  else    printf(",%d",a[i]);}    return 0;}int max_value(int a[], int n){  int max=a[0];              //定义max  for(int i=1;i<n;i++)    {if(a[i]>max)        {max=a[i];}}    return max;}int max_index(int idx[], int a[], int n)//将a[]中所有最大值所在位置的索引(下标)存放在idx中,返回idx[]中元素的个数{ int i,count=0;                        //元素个数count int max=max_value(a,n); for(i=0;i<n;i++)    {     if(a[i]==max)     idx[count++]=i;//把数存放在数组    } return count;    }int main(){    int array[MAX_SIZE], size;    int index[MAX_SIZE], idx_size;    size = get_array(array);    idx_size = max_index(index, array, size);    printf("maximum number is %d, ", max_value(array, size));    printf("whose positions are:");    put_array(index, idx_size);    return 0;}

Problem 1146

#include <stdio.h>#include <math.h>double func(double x){    if(x<0)        return -x;    if(x>=0&&x<1)        return sin(2*x);    if(x>=1&&x<5)        return sqrt(x*x*x+x);    if(x>=5)        return 2*x+10;}int output(int n, double x){    printf("case %d:y=%.6g.\n",n,x);}int main(){    int i, cases;    double x;    scanf("%d", &cases);    for(i = 1; i <= cases; i++)    {        scanf("%lf", &x);        output(i, func(x));    }    return 0;}

Problem 1149

#include<stdio.h>#include<string.h>int main(){    int n;    scanf("%d",&n);    getchar();    char a[1000] = {"\0"};    for(int i=0;i<n;i++)    {        scanf("%[^\n]",a);        getchar();        printf("case %d:length=",i+1);        printf("%d.\n",strlen(a));    }    return 0;}

Problem 1152

#include <stdio.h>#include <stdlib.h>#define MAX_SIZE 105int get_matrix(int mtx[][MAX_SIZE], int m, int n){    int i,j;    for(i=0;i<m;i++)    {        for(j=0;j<n;j++)        {            scanf("%d",&mtx[i][j]);        }    }    return 0;}int put_array(int arr[], int n){    int i;    for(i=0;i<n;++i)    {        if(i)        putchar(' ');        printf("%d",arr[i]);    }    putchar('\n');    return 0;}int count_sum(int arr[], int mtx[][MAX_SIZE], int m, int n){    int i,j,sum=0;    for(i=0;i<m;i++)    {        sum=0;        for(j=0;j<n;j++)        {            sum+=mtx[i][j];        }        arr[i]=sum;    }    return 0;} int main(){    int i, cases, sum[MAX_SIZE];    int m, n, matrix[MAX_SIZE][MAX_SIZE];    scanf("%d", &cases);    for(i = 1; i <= cases; i++)    {        scanf("%d%d", &m, &n);        get_matrix(matrix, m, n);        count_sum(sum, matrix, m, n);        printf("case %d:", i);        put_array(sum, m);    }    return 0;}

点击全文阅读


本文链接:http://zhangshiyu.com/post/181631.html

<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

关于我们 | 我要投稿 | 免责申明

Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1