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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值