关于#字符串#的问题,如何解决?

小明和小王是一对好伙伴,也有共同的爱好,都喜欢看特工电影,特别崇拜特工之间的密码交流,于是两位小朋友也自己想了一个暗号密码,输入一串无规则字符串,字符串看似杂乱无章,实际上却隐藏着两位小朋友彼此的交流信息:当遇到数字字符的时候,数字的大小就表示从当前位置往后多少位的字符是有效信息,把所有的有效信息连在一起就是字符串中隐藏的密码(0表示空字符)。
【样例输入】
deqw2xhde3njiak0dea4deqm5deaea6qwplan
【样例输出】
hi man

遍历字符串,找到数字字符,转换为数字,然后输出当前位置加上这个数字的字符

#include <iostream>
using namespace std;
int main()
{
    char s[10000] = {'\0'};
    gets(s);
    int i=0;
    while(s[i] != '\0')
    {
        if(s[i] >='0' && s[i] <='9')
        {
             int n = s[i] - '0';
             if(n==0)
                cout<<' ';
             else
                cout<<s[i+n]<<' ';
        }
        i++;
    }
}

望采纳

#include<bits/stdc++.h>
using namespace std;
int main()
{
    char s[10000];
    cin>>s;
    for(int i=0;i<=strlen(s);i++)
    if(s[i]>='0'&&s[i]<='9')
    {
        int n=s[i]-'0';
        if(n==0)
        cout<<' ';
        else
        cout<<s[i+n];
    }
}

可以看下cpp参考手册中的 c++-字符串