题目大意:
- 给定DNA序列和培养皿序列;
- 某一时刻一个培养皿前后加自身的密度和为下一时刻该培养皿的密度序号;
- 根据密度序号找到DNA序列中相应位置的数字,即下一时刻该培养皿的密度
总结点:
- memcpy(目的数组,原数组,字节数),主要是字节数,C++中int类型为4字节。
- 数组声明可以改成
int firstLine[40] = {0}; firstLine[20] = 1;
- 输出格式最后不要多一行空行。
Accepted代码:
#include <stdio.h>
#include <cstring>
//#define LOCAL
#define DNASIZE 10 //DNA序列大小
#define LINESIZE 40 //培养皿个数
#define LINECOUNT 50 //输出50行
int DNA[DNASIZE];
const int firstLine[LINESIZE] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int main()
{
#ifdef LOCAL
freopen("data.txt", "r", stdin);
#endif // LOCAL
int n;
scanf("%d", &n);
while(n--) //对每组数据操作
{
int currentLine[LINESIZE];
int nextLine[LINESIZE];
memcpy(currentLine, firstLine, 40 * 4);//n为字节数
for(int i = 0; i < DNASIZE; i++)//读入DNA序列
{
scanf("%d", &DNA[i]);
}
for(int j = 0; j < LINECOUNT; j++)
{
for(int i = 0; i < LINESIZE; i++)//输出当前行
{
switch(currentLine[i])
{
case 0:printf(" ");break;
case 1:printf(".");break;
case 2:printf("x");break;
case 3:printf("W");break;
}
}
printf("\n");
for(int i = 0; i < 40; i++)//计算下一行
{
if(i==0)
nextLine[i] = DNA[currentLine[i] + currentLine[i+1]];
else if(i==39)
nextLine[i] = DNA[currentLine[i-1] + currentLine[i]];
else
nextLine[i] = DNA[currentLine[i-1] + currentLine[i] + currentLine[i+1]];
}
memcpy(currentLine, nextLine, 40*4);
}
//printf("\n"); //wrong answer
if(n != 0) //accepted
printf("\n");
}
return 0;
}