UvaOJ 457

1.英文阅读问题:

In any given culture dish, let K be the sum of that culture dish's density and the densities of the dish immediately to the left and the dish immediately to the right. Then, by the next day, that dish will have a population density of DNA[K].

K=dish[i-1]+dish[i]+dish[i+1],三个值的和。

2.复制整形数组的问题:

整形数组的复制不能使用strcpy()函数,因为此函数要求的指针类型为char,不是int,使用时会报错;正确的方法是使用memcpy()函数,但是有一点需要注意。count的值必须使用sizeof(dest)进行赋值。如果使用sizeof(src)进行赋值,就算两个数组的大小一样,也还是会报错。以下是memcpy()函数的说明。

 

memcpy

原型:extern void *memcpy(void *dest, void *src, unsigned int count);

用法:#include <string.h>

     功能:由src所指内存区域复制count个字节到dest所指内存区域。

     说明:srcdest所指内存区域不能重叠,函数返回指向dest的指针。


     推荐一个C语言函数速查网站:

     http://www.kuqin.com/clib/

 

#include <stdio.h>
#include <string.h>

void linear(int *dish, int *DNA)
{
	int i, temp[45];
	memcpy(temp,dish,sizeof(temp));
	for(i=1;i<=40;i++)
		dish[i]=DNA[temp[i-1]+temp[i]+temp[i+1]];
}

int main()
{
	int dish[45], DNA[10], n, i, j;
	scanf("%d", &n);
	while(n--)
	{
		memset(dish,0,sizeof(dish));
		dish[20]=1;
		for(i=0;i<10;i++)
			scanf("%d",&DNA[i]);
		for(i=0;i<50;i++)
		{
			for(j=1;j<=40;j++)
			{
				if(dish[j]==0)
					printf(" ");
        			if(dish[j]==1)
					printf(".");
				if(dish[j]==2)
					printf("x");
				if(dish[j]==3)
					printf("W");
			}
			printf("\n");
			linear(dish,DNA);
		}	
		if(n!=0)
			printf("\n");
	}
	return 0;
}

你可能感兴趣的:(uva)