POJ 1302

作者: vanadia | 来源:发表于2016-08-31 21:07 被阅读0次

POJ 1302

题意

给出一串字符,求变异后的字符串

思路

  1. 如果是字母,这当前字母的位置变为后面需要变异字母的总和
  2. 如果是数字1-9,则当前数字改变为当前数字减1,并跳过当前数字的个数继续向后执行。

英语不太好,网上查的题意。
递归也不太会,网上学习的poj1302解题报告

#include <iostream>
#include <cstring>

using namespace std;

char ss[15];
int n;
char str[25];
const char a1[] = "ENDOFINPUT";

int solve(int p){
    if(str[p] == '0'|| p == n)
        return 0;
    if(str[p]>='A'&&str[p]<='Z'){
        int a = solve(p+1);
        str[p] = a%10 + '0';
        return a+1;
    }
    if(str[p]>='0'&&str[p]<='9'){
        str[p] -= 1;
        if(p+(str[p]-'0')+1<n){
            int b = solve(p+(str[p]-'0')+1);
            return b+1;
        }else{
            int c = solve(p+1);
            return c+1;
        }
    }
}

int main(){

    while(1){
        cin>>ss;
        if(strcmp(ss,a1) == 0)
            break;
        cin>>n>>str;
        cin>>ss;
        solve(0);
        cout<<str<<endl;
    }

    return 0;
}

相关文章

网友评论

      本文标题:POJ 1302

      本文链接:https://www.haomeiwen.com/subject/tqkcettx.html