| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 651 人关注过本帖
标题:浙大oj3490 String Successor 求助~~
取消只看楼主 加入收藏
LeslieCh
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2013-11-27
结帖率:77.78%
收藏
已结贴  问题点数:15 回复次数:2 
浙大oj3490 String Successor 求助~~
String Successor

--------------------------------------------------------------------------------

Time Limit: 2 Seconds      Memory Limit: 65536 KB

--------------------------------------------------------------------------------

The successor to a string can be calculated by applying the following rules:

Ignore the nonalphanumerics unless there are no alphanumerics, in this case, increase the rightmost character in the string.
The increment starts from the rightmost alphanumeric.
Increase a digit always results in another digit ('0' -> '1', '1' -> '2' ... '9' -> '0').
Increase a upper case always results in another upper case ('A' -> 'B', 'B' -> 'C' ... 'Z' -> 'A').
Increase a lower case always results in another lower case ('a' -> 'b', 'b' -> 'c' ... 'z' -> 'a').
If the increment generates a carry, the alphanumeric to the left of it is increased.
Add an additional alphanumeric to the left of the leftmost alphanumeric if necessary, the added alphanumeric is always of the same type with the leftmost alphanumeric ('1' for digit, 'A' for upper case and 'a' for lower case).

Input
There are multiple test cases. The first line of input is an integer T ≈ 10000 indicating the number of test cases.

Each test case contains a nonempty string s and an integer 1 ≤ n ≤ 100. The string s consists of no more than 100 characters whose ASCII values range from 33('!') to 122('z').

Output
For each test case, output the next n successors to the given string s in separate lines. Output a blank line after each test case.

Sample Input
4
:-( 1
cirno=8 2
X 3
/**********/ 4

Sample Output
:-)

cirno=9
cirnp=0

Y
Z
AA

/**********0
/**********1
/**********2
/**********3



代码:
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<iostream>
using namespace std;
char f(char x)
{
    if(x=='9'){return '0';}
    if(x=='z'){return 'a';}
    if(x=='Z'){return 'A';}
    else
    {return 'n';}
}
int main()
{
    int T,i,n,j,k,flag,q;
    char s[105],c[105];
    cin>>T;
    for(i=0;i<T;i++)
    {
        memset(c,0,sizeof(c));
        scanf("%s%d",s,&n);
        for(q=0;q<n;q++)
        {     
        k=0;flag=0;
        for(j=strlen(s)-1;j>=0;j--)
        {
            if(isalnum(s[j]))
            {flag=1;}
            c[k]=s[j];
            k++;
        }
        if(flag==1)
        {
            for(j=0;j<strlen(s);j++)
            {
                if(isalnum(c[j])){break;}
            }
            if(f(c[j])!='n')//jin wei
            {
                c[j]=f(c[j]);
                j++;
                while(j<strlen(s))
                {
                    if(isalnum(c[j]))
                    {
                        if(f(c[j])!='n')
                        {c[j]=f(c[j]);}
                        else
                     {c[j]++;break;}
                    }
                    j++;
                }
                if(j>=strlen(s))
                {
                    for(j=strlen(s)-1;j>=0;j--)
                    {
                        if(isalnum(c[j])){break;}
                    }
                    for(k=j+1;k<=strlen(s)-1;k++)
                    {
                        c[k+1]=c[k];
                    }
                    c[k+1]='\0';
                    if(isdigit(c[j]))
                    {c[j+1]='1';}
                    else
                    {c[j+1]=c[j];}
                }
            }
            else
            {c[j]++;}
        }
        else
        {c[0]++;}
        k=0;
        for(j=strlen(c)-1;j>=0;j--)
        {
            s[k]=c[j];
            k++;
            printf("%c",c[j]);
        }
        printf("\n");
        }
    }
}


试了好多数据都找不出错的,提交上去就是不对。。。求指点~!        
                    
搜索更多相关主题的帖子: character following increase Memory unless 
2014-03-28 16:38
LeslieCh
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2013-11-27
收藏
得分:0 
.
2014-03-28 16:39
LeslieCh
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2013-11-27
收藏
得分:0 
2014-03-30 12:56
快速回复:浙大oj3490 String Successor 求助~~
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016963 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved