C语言上机练习二

时间:2023-10-06 10:56:55
 //
#include<stdio.h>
int main()
{
int a,b;
while(~scanf("%d%d",&a,&b))
printf("%d\n",a+b);
}
 //
#include<stdio.h>
#include<string.h>
char s[];
int main()
{
int i,t,d,x,m;
while(gets(s)!=NULL)
{
t=strlen(s);
for(i=d=x=m=; i<t; ++i)
{
if(s[i]>='A'&&s[i]<='Z')
d++;
if(s[i]>='a'&&s[i]<='z')
x++;
if(s[i]>=''&&s[i]<='')
m++;
}
printf("%d %d %d\n",d,x,m);
}
}
 //
#include<stdio.h>
int main()
{
int a,b,r,t,x,y;
while(~scanf("%d%d",&a,&b))
{
x=a;
y=b;
if(a<b)
{
t=a;
a=b;
b=t;
}
do
{
r=a%b;
a=b;
b=r;
}while(r);
x/=a;
y/=a;
printf("%d %d\n",a,x*y*a);
}
}
 //
#include<stdio.h>
int main()
{
int i,s,n;
while(~scanf("%d",&n))
{
for(i=s=; i<=n; ++i)
s*=i;
printf("%d\n",s);
}
}
 //
#include<stdio.h>
#include<string.h>
int a[];
int main()
{
    int n,i,j,len=;
    while(~scanf("%d",&n))
    {
        memset(a,,sizeof a);
        for(i=,a[]=,len=; i<=n; ++i)
        {
            for(j=; j<=len; ++j)
            {
                if(j)
                {
                    a[j]=a[j]*i+a[j-]/;
                    a[j-]%=;
                }
                else
                    a[j]*=i;
            }
            if(a[len])
                len++;
            
        }
        for(i=len-; i>=; --i)
            if(i==len-)
                printf("%d",a[i]);
            else
                printf("%04d",a[i]);
        printf("\n");
    }
}
 //
#include<stdio.h>
int a[];
int main()
{
int i,n;
while(~scanf("%d",&n))
{
for(i=; i<n; ++i)
scanf("%d",&a[i]);
for(i=n-; i>=; --i)
if(i)
printf("%d ",a[i]);
else
printf("%d",a[i]);
printf("\n");
}
}
 //
#include<stdio.h>
int a[];
int main()
{
int i,j,s,n;
while(~scanf("%d",&n))
{ for(j=,i=; i<n; ++i)
if(!(n%i))
a[j++]=i;
for(i=s=; i<j; ++i)
s+=a[i];
if(s==n)
{
printf("Yes\n");
for(i=; i<j; ++i)
if(i)
printf(" %d",a[i]);
else
printf("%d",a[i]);
printf("\n");
}
else
printf("No\n");
}
}
 //
#include<stdio.h>
int a[];
int main()
{
int i,j,s,t,n;
while(~scanf("%d",&n))
{
for(i=; i<n; ++i)
scanf("%d",&a[i]);
for(i=; i<n-; ++i)
for(j=; j<n--i; ++j)
if(a[j]>a[j+])
{
t=a[j];
a[j]=a[j+];
a[j+]=t;
}
for(i=; i<n; ++i)
if(i)
printf(" %d",a[i]);
else
printf("%d",a[i]);
printf("\n");
}
}
 #include<stdio.h>
#include<string.h>
int a[][];
int main()
{
int n,x,y,t;
while(~scanf("%d",&n))
{
memset(a,,sizeof a);
t=a[x=][y=n-]=n*n;
while(t>)
{
while(x+<n&&!a[x+][y]) a[++x][y]=--t;
while(y->=&&!a[x][y-]) a[x][--y]=--t;
while(x->=&&!a[x-][y]) a[--x][y]=--t;
while(y+<n&&!a[x][y+]) a[x][++y]=--t;
}
for(x=; x<n; ++x)
{
for(y=; y<n; ++y)
if(y)
printf(" %d",a[x][y]);
else
printf("%d",a[x][y]);
printf("\n");
}
}
}
 //1010(百度康托展开,可以得到你想要的)
#include<stdio.h>
#include<string.h>
char s[];
int a[]={,,,,,,};
int main()
{
    int n,len,i,j,sum,t;
    while(~scanf("%d",&n))
    {
        getchar();
        while(n--)
        {
            gets(s);
            len=strlen(s);
            for(i=sum=; i<len; ++i)
            {
                for(j=i+,t=; j<len; ++j)
                    if(s[j]<s[i])
                        ++t;
                sum+=t*a[i];
            }
            printf("%d\n",++sum);
        }
    }
}