C语言上机练习二

1 //1001
2 #include<stdio.h>
3 int main()
4 {
5     int a,b;
6     while(~scanf("%d%d",&a,&b))
7         printf("%d\n",a+b);
8 }
 1 //1002
 2 #include<stdio.h>
 3 #include<string.h>
 4 char s[1000];
 5 int main()
 6 {
 7     int i,t,d,x,m;
 8     while(gets(s)!=NULL)
 9     {
10         t=strlen(s);
11         for(i=d=x=m=0; i<t; ++i)
12         {
13             if(s[i]>='A'&&s[i]<='Z')
14                 d++;
15             if(s[i]>='a'&&s[i]<='z')
16                 x++;
17             if(s[i]>='0'&&s[i]<='9')
18                 m++;
19         }
20         printf("%d %d %d\n",d,x,m);
21     }
22 }
 1 //1003
 2 #include<stdio.h>
 3 int main()
 4 {
 5     int a,b,r,t,x,y;
 6     while(~scanf("%d%d",&a,&b))
 7     {
 8         x=a;
 9         y=b;
10         if(a<b)
11         {
12             t=a;
13             a=b;
14             b=t;
15         }
16         do
17         {
18             r=a%b;
19             a=b;
20             b=r;
21         }while(r);
22         x/=a;
23         y/=a;
24         printf("%d %d\n",a,x*y*a);
25     }
26 }
 1 //1004
 2 #include<stdio.h>
 3 int main()
 4 {
 5     int i,s,n;
 6     while(~scanf("%d",&n))
 7     {
 8         for(i=s=1; i<=n; ++i)
 9             s*=i;
10         printf("%d\n",s);
11     }
12 }
 1 //1005
 2 #include<stdio.h>
 3 #include<string.h>
 4 int a[10000];
 5 int main()
 6 {
 7     int n,i,j,len=0;
 8     while(~scanf("%d",&n))
 9     {
10         memset(a,0,sizeof a);
11         for(i=2,a[0]=1,len=1; i<=n; ++i)
12         {
13             for(j=0; j<=len; ++j)
14             {
15                 if(j)
16                 {
17                     a[j]=a[j]*i+a[j-1]/10000;
18                     a[j-1]%=10000;
19                 }
20                 else
21                     a[j]*=i;
22             }
23             if(a[len])
24                 len++;
25             
26         }
27         for(i=len-1; i>=0; --i)
28             if(i==len-1)
29                 printf("%d",a[i]);
30             else
31                 printf("%04d",a[i]);
32         printf("\n");
33     }
34 }
 1 //1006
 2 #include<stdio.h>
 3 int a[100000];
 4 int main()
 5 {
 6     int i,n;
 7     while(~scanf("%d",&n))
 8     {
 9         for(i=0; i<n; ++i)
10             scanf("%d",&a[i]);
11         for(i=n-1; i>=0; --i)
12             if(i)
13                 printf("%d ",a[i]);
14             else
15                 printf("%d",a[i]);
16         printf("\n");
17     }
18 }
 1 //1007
 2 #include<stdio.h>
 3 int a[100000];
 4 int main()
 5 {
 6     int i,j,s,n;
 7     while(~scanf("%d",&n))
 8     {
 9 
10         for(j=0,i=1; i<n; ++i)
11             if(!(n%i))
12                 a[j++]=i;
13         for(i=s=0; i<j; ++i)
14             s+=a[i];
15         if(s==n)
16         {
17             printf("Yes\n");
18             for(i=0; i<j; ++i)
19                 if(i)
20                     printf(" %d",a[i]);
21                 else
22                     printf("%d",a[i]);
23             printf("\n");
24         }
25         else
26             printf("No\n");
27     }
28 }
 1 //1008
 2 #include<stdio.h>
 3 int a[100000];
 4 int main()
 5 {
 6     int i,j,s,t,n;
 7     while(~scanf("%d",&n))
 8     {
 9         for(i=0; i<n; ++i)
10             scanf("%d",&a[i]);
11         for(i=0; i<n-1; ++i)
12             for(j=0; j<n-1-i; ++j)
13                 if(a[j]>a[j+1])
14                 {
15                     t=a[j];
16                     a[j]=a[j+1];
17                     a[j+1]=t;
18                 }
19         for(i=0; i<n; ++i)
20             if(i)
21                 printf(" %d",a[i]);
22             else
23                 printf("%d",a[i]);
24         printf("\n");
25     }
26 }
 1 #include<stdio.h>
 2 #include<string.h>
 3 int a[10][10];
 4 int main()
 5 {
 6     int n,x,y,t;
 7     while(~scanf("%d",&n))
 8     {
 9         memset(a,0,sizeof a);
10         t=a[x=0][y=n-1]=n*n;
11         while(t>1)
12         {
13             while(x+1<n&&!a[x+1][y])  a[++x][y]=--t;
14             while(y-1>=0&&!a[x][y-1]) a[x][--y]=--t;
15             while(x-1>=0&&!a[x-1][y]) a[--x][y]=--t;
16             while(y+1<n&&!a[x][y+1])  a[x][++y]=--t;
17         }
18         for(x=0; x<n; ++x)
19         {
20             for(y=0; y<n; ++y)
21                 if(y)
22                     printf(" %d",a[x][y]);
23                 else
24                     printf("%d",a[x][y]);
25             printf("\n");
26         }
27     }
28 }
 1 //1010(百度康托展开,可以得到你想要的)
 2 #include<stdio.h>
 3 #include<string.h>
 4 char s[8];
 5 int a[8]={5040,720,120,24,6,2,1};
 6 int main()
 7 {
 8     int n,len,i,j,sum,t;
 9     while(~scanf("%d",&n))
10     {
11         getchar();
12         while(n--)
13         {
14             gets(s);
15             len=strlen(s);
16             for(i=sum=0; i<len; ++i)
17             {
18                 for(j=i+1,t=0; j<len; ++j)
19                     if(s[j]<s[i])
20                         ++t;
21                 sum+=t*a[i];
22             }
23             printf("%d\n",++sum);
24         }
25     }
26 }

 

posted @ 2016-11-11 23:45  Posase  阅读(256)  评论(0编辑  收藏  举报