POJ 1302 Blue Gene, Jr.解题报告

Blue Gene, Jr.
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 394 Accepted: 260

Description

Inspired by IBM's Blue Gene project, the CEO of Universal Biological Machinery (UBM), has called on you, UBM's top software engineer, to develop a program that will calculate the mutation of the Areopagus-virus, a virus discovered on Mars by your company's privately-subsidized (top-secret) space program.

Input

Input to this problem will consist of a (non-empty) series of up to 100 data sets. Each data set will be formatted according to the following description, and there will be no blank lines separating data sets. 
A single data set has 3 components: 

  1. Start line - A single line, "START N", where 1 <= N <= 20. 
  2. Viral code - A sequence of N alphanumeric characters. Alphanumeric characters will consist of an uppercase letter (A-Z) or a digit (0-9). 
  3. End line - A single line, "END" 

Following the final data set will be a single line, "ENDOFINPUT". 

Output

For each data set, there will be exactly one output set, and there will be no blank lines separating output sets. 

A single output set consists of a single line of the viral code after it has stabilized (through mutating). 

The viral code will mutate according to the following rules: 

  1. Initially the first viral segment to mutate begins with the first alphanumeric character of the viral code and ends with the rightmost alphanumeric character of the code. 
  2. If the first alphanumeric character of a viral segment is a letter (A-Z), that alphanumeric character is considered "unstable", and will mutate into n, where n is the number of mutations that occur to the viral segment immediately to the unstable alphanumeric character's right (see #5), unless n is greater than 9, in which case the unstable alphanumeric character will mutate into n % 10. Also, if there is no viral segment immediately to the right of the unstable alphanumeric character, the unstable alphanumeric character will mutate into 0. 
  3. If the first alphanumeric character of a viral segment, n, is a positive number (1-9), that alphanumeric character is also considered "unstable", and will mutate into n-1. It also causes the viral segment beginning with the alphanumeric character n alphanumeric characters to its right and ending with the rightmost alphanumeric character of the viral code to mutate. If there is no alphanumeric character n alphanumeric characters to its right, then the viral segment immediately to its right (see #5), if one exists, will mutate. 
  4. If the first alphanumeric character of a viral segment is 0, that alphanumeric character is considered "stable", and will not mutate (the alphanumeric character will remain a 0 and a mutation will not be considered to have occurred). 
  5. A viral segment immediately to the right of an alphanumeric character begins with the alphanumeric character one position to its right and ending with the rightmost alphanumeric character of the viral code. 

Sample Input

START 1
A
END
START 4
A1B2
END
START 15
A3B2CCC4AD1232R
END
START 15
0ABCDEFGHIJKLMN
END
START 11
ABCDEFGHIJK
END
START 10
9AAAAAAAAA
END
ENDOFINPUT

Sample Output

0
3011
82B26543AD11310
0ABCDEFGHIJKLMN
09876543210
8AAAAAAAA0
-----------------------------------------------------------
> 大概意思是
> 有一段字符串,如果是字母开头的,此字母就变成后面变异数的总和
> 如果以数字开头,此数字变成N-1,然后从后面第N个开始变异
> 如果以0开头,就不变。
> 
> 是个递归的过程
补充一下,
第一种情况是向后移一位,
第二种假设数字为n,就变成n-1,如果后面还有n位,就移到n位再继续转变,否则右移一位开始转变
当前位为0直接结束
这道题o----很坑爹。。。
 
---------------------------------
#include <stdio.h>
#include <string.h>


int n;
char string[21];


int searching(int pos)
{
    if (string[pos] == '0' || pos == n) 
	{
        return 0;
    }
    if (string[pos] >= 'A' && string[pos] <= 'Z') 
	{
        int x = searching(pos+1);
        if (x > 9) 
            string[pos] = (x % 10) + '0';
        else
            string[pos] = x + '0';


        return 1 + x;
    }
    if (string[pos] >= '1' && string[pos] <= '9') 
	{
        if (pos + string[pos] - '0' < n) 
		{
            int x = searching(pos+string[pos]-'0');
            string[pos] -= 1;
            return 1 + x;
        }
        else 
		{
            int x = searching(pos+1);
            string[pos] -= 1;
            return 1 + x;
        }
    }
}


int main()
{
    char str[10];
    while (1) 
	{
        scanf("%s", str);
        if (strcmp(str, "ENDOFINPUT") == 0)
            break;
        scanf("%d\n",&n);
        scanf("%s", string);
        scanf("%s", str);


        searching(0);
        printf("%s\n", string);
    }


    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值