UVA457

题目大意:

  • 给定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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值