题目链接:http://acm.sdibt.edu.cn:8080/judge/contest/view.action?cid=398#problem/F

G – Rotating Sentences
#include <stdio.h>
#include <string.h>
int main()
{
   char word[105][105];
   int i=0,j,k=0,n,sign[105],max=0;
   memset(word,' ',sizeof(word));
   while(gets(word[i])!=0)
   {
	   sign[i]=strlen(word[i]);
	   if(sign[i]>max)
	   {
		   max=sign[i];
	   }
	   i++;
   }
   n=i;
   for(i=0;i<max;i++)
   {
	   for(j=n-1;j>=0;j--)
	   {
		   if(word[j][i]!=0)
			   printf("%c",word[j][i]);
		   else
			   printf(" ");
	   }
	   printf("\n");
    }
    return 0;
}
H – Marvelous Mazes
#include <stdio.h>
#include <string.h>
char word[200];
int main()
{       
	int c=0,n,i,j;
          while(gets(word)!=0)
	{
                   n=strlen(word);
		 for(i=0;i<n;i++)
		 {
			 if(word[i]>='0'&&word[i]<='9')
				 c=c+word[i]-48;
			  else   if(word[i]!='!')
			  {       if(word[i]=='b')
			           word[i]=' ';
				  for(j=0;j<c;j++)
					  printf("%c",word[i]);
				  c=0;
			  }
			  else if(word[i]=='!')
				  printf("\n");
		 }
		 memset(word,0,sizeof(word));
		 printf("\n");
	 }
	 return 0;
}
I – Triangle Wave
#include <stdio.h>
#include <string.h>
int main()
{
	int T,amp,fre,i,j,k;
	while(scanf("%d",&T)!=EOF)
	{
		while(T)
		{
			scanf("%d%d",&amp,&fre);
                           for(i=0;i<fre;i++)
			{
				for(j=1;j<=amp;j++)
				{   for(k=0;k<j;k++)
	 			       printf("%d",j);
				    printf("\n");
				}
				for(j=amp-1;j>=1;j--)
				{   for(k=0;k<j;k++)
	 			         printf("%d",j);
				    printf("\n");
				}
			         if(i!=fre-1)
			         printf("\n");
			}
			if(T!=1)
			  printf("\n");
			T--;
		}
	}
	return 0;
}
J – Hangman Judge
#include <stdio.h>
#include <string.h>
int  main()
{   
	int n1,n2,number,counta=0,countb=0,flag=0,i,j,k=0;
	char a[200],b[200];
	while(scanf("%d",&number),number!=-1)
	{    getchar();
		 memset(a,0,sizeof(a));
		 memset(a,0,sizeof(b));
	          counta=countb=0;
		 flag=0;
		 k=0;
                   gets(a);
		 gets(b);
                   n1=strlen(a);
		 n2=strlen(b);
		 for(i=0;i<n2;i++)
		 {
                      for(j=0;j<n1;j++)
                            if(b[i]==a[j])
		          {
					  counta++;
					  a[j]=0;
					  flag=1;
			 }
			if(flag==1)
                                  countb++;
			flag=0;
			if((i+1)-countb==7&&counta!=n1)
			{
				printf("Round %d\nYou lose.\n",number);
				k=1;
				break;
			}
			if((i+1)-countb<=7&&counta==n1)
			{
            	                  printf("Round %d\nYou win.\n",number);
				k=1;
				break;
			}
		  } 
			if(k==0)
	printf("Round %d\nYou chickened out.\n",number);
	} 
	return 0;
}
K – The Collatz Sequence
#include <stdio.h>
int main()
{
   long A,limit,A0,limit0;
   int n=0,k=0;
   while(scanf("%ld%ld",&A,&limit),A!=-1&&limit!=-1)
   {                 k=0;
                     n++;
		   A0=A;
		  limit0=limit;
                    while(A!=1&&A<=limit0)
		  {
			  if(A%2==0)
				  A=A/2;
			  else
                                      A=A*3+1;
		           k++;
		  }
		  if(A==1)
			  k++;
printf("Case %d: A = %ld, limit = %ld, number of terms = %d\n",n,A0,limit0,k);
   }
   return 0;
}

L – Linear Cellular Automata

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int DNA[10];
char dish1[60],dish2[60];
int number(char a)
{
    if(a==' ') return 0;
	if(a=='.') return 1;
	if(a=='x') return 2;
	if(a=='W') return 3;
}
char f(int n)
{
	if(n==0) return ' ';
	if(n==1) return '.';
	if(n==2) return 'x';
	if(n==3) return 'W';
}
char ve(char a,char b,char c)
{
	int sum=0;
	char ch;
	sum=number(a)+number(b)+number(c);
	ch=f(DNA[sum]);
	return ch;
}
int main()
{
  int T,i,j,k,p1,p2;
  scanf("%d",&T);

	for(k=0;k<T;k++)
	{
		memset(dish1,0,sizeof(dish1));
		p1=p2=0;
                  for(i=0;i<10;i++)
		{
	    	           scanf("%d",&DNA[i]);
			  if(DNA[i]==0)
				  p1++;
			  if(DNA[i]==3)
				  p2++;
		}
	         for(i=0;i<40;i++)
		{
		   if(i==19)
		    	  dish1[i]='.';
		   else
		    	  dish1[i]=' ';
		}
	         puts(dish1);
	         for(i=1;i<50;i++)
		{
		           memset(dish2,0,sizeof(dish2));
		           for(j=0;j<40;j++)
		  	  {
			     if(j==0)
				     dish2[j]=ve(' ',dish1[j],dish1[j+1]);
			     if(j==39)
                                         dish2[j]=ve(dish1[j-1],dish1[j],' ');
		 	     if(j!=0&&j!=39)
		              dish2[j]=ve(dish1[j-1],dish1[j],dish1[j+1]);
			 }
		          puts(dish2);
		          memset(dish1,0,sizeof(dish1));
		          strcpy(dish1,dish2);
		}
		if(k!=T-1)
			printf("\n");
	}
  system("pause");
  return 0;
}

发表评论

电子邮件地址不会被公开。

Post Navigation