zoukankan      html  css  js  c++  java
  • 如果奇迹有颜色,那么一定是暴力or模拟比较6

    模拟就是一个思想,给你一个东西,没有很好的算法去解决,只需要计算机去暴力,优雅的暴力就可以叫算法了

    主要还是考大家的代码能力,这次题目应该不需要任何前置技能。

    1001

    Time Limit(Common/Java):1000MS/3000MS     Memory Limit:65536KByte
    Total Submit: 27            Accepted: 9
     

    Description

     

    本题要求实现一种数字加密方法。首先固定一个加密用正整数A,对任一正整数B,将其每1位数字与A的对应位置上的数字进行以下运算:对奇数位,对应位的数字相加后对13取余――这里用J代表10、Q代表11、K代表12;对偶数位,用B的数字减去A的数字,若结果为负数,则再加10。这里令个位为第1位。

    Input

     

    输入在一行中依次给出A和B,均为不超过100位的正整数,其间以空格分隔。

    Output

     

    在一行中输出加密后的结果。

    Sample Input

     

    1234567 368782971

    Sample Output

    3695Q8118

    Uploader

    crq

    A就是按照题目所描述的模拟,TYX的代码还是很棒的,直接拿来用

    #include<stdio.h>
    #include<string.h>
    int main()
    {
        char s[120],ss[120];
        int hh[120]={0};
        int i,j;
        scanf("%s %s",s,ss);
        int len1=strlen(s);
        int len2=strlen(ss);
        for(i=len2-1,j=1;i>=0;i--,j++)
        {
            hh[j]=ss[i]-'0';
        }
        for(i=len1-1,j=1;i>=0;i--,j++)
        {
            if(j%2==0)
            {hh[j]-=(s[i]-'0');
            if(hh[j]<0)hh[j]+=10;}
            else hh[j]=(hh[j]+(s[i]-'0'))%13;
        }
        if(len2<len1)len2=len1;
        for(i=len2;i>0;i--)
        {
            if(hh[i]<10)printf("%d",hh[i]);
            else if(hh[i]==10)printf("J");
            else if(hh[i]==11)printf("Q");
            else if(hh[i]==12)printf("K");
        }
        printf("
    ");
    }

    1002

     

    Time Limit(Common/Java):1000MS/3000MS     Memory Limit:65536KByte
    Total Submit: 13            Accepted: 5

    Description

     

    本题要求将给定的N个正整数按非递增的顺序,填入“螺旋矩阵”。所谓“螺旋矩阵”,是指从左上角第1个格子开始,按顺时针螺旋方向填充。要求矩阵的规模为m行n列,满足条件:m*n等于N;m>=n;且m-n取所有可能值中的最小值。

    Input

     

    输入在第1行中给出一个正整数N,第2行给出N个待填充的正整数。所有数字不超过104,相邻数字以空格分隔。

    Output

     

    输出螺旋矩阵。每行n个数字,共m行。相邻数字以1个空格分隔,行末不得有多余空格。

    Sample Input

    12
    37 76 20 98 76 42 53 95 60 81 58 93

    Sample Output

    98 95 93
    42 37 81
    53 20 76
    58 60 76

    Uploader

    crq

    螺旋矩阵其实就是先往右,再往下,再往左,再往右,再往上,一次少两排两列

    最后一个不确定往哪个方向走的,当已经填满n-1的时候填

    #include <stdio.h>
    #include <algorithm>
    int cmp(int a,int b)
    {
        return a>b;
    }
    using namespace std;
    int a[10010],c[1001][1001];
    int main()
    {
        int N,m,n,i;
        scanf("%d",&N);
        for(i=0; i<N; i++)
            scanf("%d",&a[i]);
        if(N==1)
        {
            printf("%d
    ",a[0]);
        }
        else
        {
            int f=200000000;
            for(i=1; i*i<=N; i++)
                if(N/i*i==N&&f>N/i-i)
                {
                    f=N/i-i;
                    n=i;
                    m=N/i;
                }
            sort(a,a+N,cmp);
            int j=1,now=0,U=1,D=m,L=1,R=n;
            i=1;
            while(now<N)
            {
                while(j<R&&now<N)
                {
                    c[i][j]=a[now++];
                    j++;
                }
                while(i<D&&now<N)
                {
                    c[i][j]=a[now++];
                    i++;
                }
                while(j>L&&now<N)
                {
                    c[i][j]=a[now++];
                    j--;
                }
                while(i>U&&now<N)
                {
                    c[i][j]=a[now++];
                    i--;
                }
                i++;
                j++;
                U++,D--;
                L++,R--;
                if(now==N-1)
                    c[i][j]=a[now++];
            }
            for(i=1; i<=m; i++)
            {
                printf("%d",c[i][1]);
                for(j=2; j<=n; j++)
                    printf(" %d",c[i][j]);
                printf("
    ");
            }
        }
        return 0;
    }

    1003

     

    Time Limit(Common/Java):1000MS/10000MS     Memory Limit:65536KByte
    Total Submit: 9            Accepted: 7

    Description

     

    hqj是tzc acm 2009集训队中唯一一个数学系的同学,因此经常有人向他请教数学问题,某日wk向他请教一道概率题目,他浪费了3页草稿纸都没解出来,下面的题目也是概率题,如果你做出来了,你肯定能够超越hqj。你能编个程序帮他解决吗?

    给定n个元件已知它们是并联还是串联,告诉你各个元件正常工作的概率,求整个电路正常工作的概率。

    Input

     

    第一行输入t,表示有t组数据,每组数据的第一行包含一个字符串s和一个正整数n(使用若干个空格分隔),当s="parallel",表示电路并联,当s="series",表示串联。第二行有n个数据,表示n个元件正常工作的概率。

    Output

     

    输出电路能正常工作的概率,输出格式参照样例输出,保留两位小数。

    Sample Input

    2

    parallel 3
    60.00% 70.00% 40.00%
    series 5
    50.00% 40.00% 20.00% 30.00% 60.00%

    Sample Output

    92.80%
    0.72%

    Hint

    在屏幕上输出一个%的方法:printf("%%")。

    Uploader

    wk

    看他是串联还是并联,分别分析求解

    #include <stdio.h>
    #include<string.h>
    int main()
    {
        char s[20],*b="parallel";
        int t,n,i,r;
        double a[300],sum;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%s",s);
            scanf("%d",&n);
            for(i=0; i<n; i++)
                scanf("%lf%%",&a[i]);
            r=strcmp(s,b);
            if(r==0)
            {
                sum=1.0;
                for(i=0; i<n; i++)
                    sum=sum*(100-a[i]);
                for(i=1; i<n; i++)
                    sum=sum*0.01;
                printf("%.2f%%
    ",(100-sum));
            }
            else
            {
                sum=1.0;
                for(i=0; i<n; i++)
                    sum=sum*a[i];
                for(i=1; i<n; i++)
                    sum=sum*0.01;
                printf("%.2f%%
    ",sum);
            }
        }
        return 0;
    }

    1004

    Time Limit(Common/Java):1000MS/3000MS     Memory Limit:65536KByte
    Total Submit: 9            Accepted: 8

    Description

     

    经过总理的多次敦促,工信部吹风,让大家期盼已久的“手机流量不清零”终于有了突破!

    中国移动、中国电信、中国联通三大运营商同时发布通知,宣布手机套餐内流量单月不清零,用户当月套餐内剩余流量可转存至次月继续使用,但在次月底失效。比如crq的套餐是每月500MB,10086告知上月剩余结转流量150MB,本月可以使用650MB。结果本月才使用了550MB,剩下的100MB就被收走了,下一个月并不能使用,要是本月使用450MB,那还有50MB能结转到下个月使用。

    现给定用户每月的套餐流量以及用户一年12个月每个月的流量使用情况,请打印出每个月的流量费用。

    第一个月时,假设之前流量剩余为0。

    Input

     

    输入数据有13行,第一行为两个整数T和M,分别为用户的套餐流量(单位为MB)以及包月费用(单位元),接下来12行每行一个整数,表示1到12月每月的流量使用值A1, A2, ..., A12(单位为KB)。

    所有流量值不超过1GB,超出部分按照每KB计1分钱。

    Output

     

    输出包含12行,每行输出一个整数,表示1到12月每月花费的流量费用(单位为分)。

    Sample Input

    500 30
    102400
    204800
    102400
    307200
    409600
    409600
    102400
    307600
    614400
    512000
    614400
    204800

    Sample Output

     

    3000
    3000
    3000
    3000
    3000
    3000
    3000
    3000
    3000
    3000
    105400
    3000

    Hint

    其中:

    1GB = 1024MB

    1MB = 1024KB

    1KB = 1024B

    Uploader

    crq

    真的模拟,把情况全都列出来就好了

    #include <stdio.h>
    int main()
    {
        int t,m,i;
        scanf("%d%d",&t,&m);
        int n=0,y[13];
        t=t*1024;
        m=m*100;
        y[0]=0;
        for(i=1; i<=12; i++)
        {
            scanf("%d",&y[i]);
            y[i]=t-y[i];
            if(y[i]+y[i-1]<0)
            {
                printf("%d
    ",m-y[i]-y[i-1]);
                y[i]=0;
            }
            else
            {
                printf("%d
    ",m);
                if(y[i]<0)y[i]=0;
            }
        }
        return 0;
    }

    1005

    Time Limit(Common/Java):1000MS/3000MS     Memory Limit:65536KByte
    Total Submit: 13            Accepted: 5

    Description

     

    小X平时喜欢看对称的东西,其中小X最喜欢回文串,每次看到回文串都会很开心。今天上课的时候小X心情不好,因此他的朋友小Y想要在书上找到回文串给X看。现在有个字符串,小Y想要在里面找到最长的回文字符子串。然而小Y的眼神一看到英文字母就头疼,你可以写个程序帮他找到最长回文子串么。

    回文串是一个正读和反读都一样的字符串,比如“level”或者“noon”等等就是回文串。

     

    Input

     

    输入有多组数据。

    每组数据输入一个字符串S(0<len<1000),S由小写字母组成。当S为“end”时输入结束。

    Output

     

    输出格式Case x: y。x表示第几组数据,y表示最长回文子串的长度。

    Sample Input

    level
    abcd
    end

    Sample Output

    Case 1: 5
    Case 2: 1

    Uploader

    kashijian

    中心扩展法求最长回文串
     
    即枚举是不是合法
    #include <stdio.h>
    #include <string.h>
    int la(char s[],int f,int d)
    {
        while(s[f]==s[d]&&f<=d)
        {
            f++;
            d--;
        }
        if(s[f]!=s[d])
            return 0;
        else
            return 1;
    }
    int max(char s[])
    {
        int l=strlen(s);
        int i,j;
        int zl=1;
        if(l==1)
        {
            return 1;
        }
        for(i=0; i<l; i++)
            for(j=i+1; j<l; j++)
                if(la(s,i,j))
                {
                    zl=(zl<j-i+1?j-i+1:zl);
                }
        return zl;
    }
    int main()
    {
        char s[1000];
        int i=1;
        while(~scanf("%s",s))
        {
            if(strcmp(s,"end")==0)break;
            printf("Case %d: %d
    ",i++,max(s));
        }
        return 0;
    }
     

    我的马拉车版本

    #include<bits/stdc++.h>
    using namespace std;
    const int N=300010;
    int n, p[N];
    char s[N], str[N];
    void kp()
    {
        int i,mx = 0,id;
        for(i=n; str[i]!=0; i++)
            str[i]=0;
        for(i=1; i<n; i++)
        {
            if( mx > i )
                p[i] = min( p[2*id-i], p[id]+id-i );
            else
                p[i] = 1;
            for(; str[i+p[i]] == str[i-p[i]]; p[i]++)
                ;
            if( p[i]+i>mx )
            {
                mx=p[i]+i;
                id=i;
            }
        }
    }
    
    void init()
    {
        str[0] = '$',str[1] = '#';
        for(int i=0; i<n; i++)
        {
            str[i*2+2] = s[i];
            str[i*2+3] = '#';
        }
        n = n*2+2;
        s[n] = 0;
    }
    int main()
    {
        int i, ans;
        int k=1;
        while(scanf("%s",s)!=EOF)
        {
            if(strcmp(s,"end")==0)break;
            n = strlen(s);
            init();
            kp();
            ans = 0;
            for(i=0; i<n; i++)
                if(p[i]>ans)ans = p[i];
            printf("Case %d: %d
    ",k++,ans-1);
        }
        return 0;
    }

    1006

    Time Limit(Common/Java):1000MS/3000MS     Memory Limit:65536KByte
    Total Submit: 5            Accepted: 4

    Description

     

    有形如:ax3+bx2+cx+d=0 这样的一个一元三次方程。给出该方程中各项的系数(a,b,c,d 均为实数),并约定该方程存在三个不同实根(根的范围在-100至100之间),且根与根之差的绝对值>=1。要求由小到大依次在同一行输出这三个实根(根与根之间留有空格),并精确到小数点后2位。

    提示:记方程f(x)=0,若存在2个数x1和x2,且x1<x2,f(x1)*f(x2)<0,则在(x1,x2)之间一定有一个根。

     

    Input

     

    一行4个数..分别表示题目中的a,b,c,d..四个数

    (注意不一定是整数哦,虽然样例是)

     

    Output

     

    一行三个数。精确到小数点后2位,分别表示题目中的三个根。

    Sample Input

     1 -5 -4 20

    Sample Output

     -2.00 2.00 5.00

    Uploader

    crq

    看起来非常难做,但是就是暴力,因为说答案精确两位两数了,从左开始枚举就是了
    #include<cstdio>
    #include<cmath>
    double a,b,c,d;
    int main()
    {
        int m=0;
        scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
        for(double x=-100.0; x<=100.0; x+=0.01)
            if(fabs(a*x*x*x+b*x*x+c*x+d)<=0.000001)
            {
                if(m)printf(" ");
                printf("%.2f",x),m=1;
            }
        return 0;
    }

    1007

    Time Limit(Common/Java):500MS/1000MS     Memory Limit:65536KByte
    Total Submit: 12            Accepted: 4

    Description

     

    Given a sequence of K integers { N1, N2, ..., NK }. A continuous subsequence is defined to be { Ni, Ni+1, ..., Nj } where 1 <= i <= j <= K. The Maximum Subsequence is the continuous subsequence which has the largest sum of its elements. For example, given sequence { -2, 11, -4, 13, -5, -2 }, its maximum subsequence is { 11, -4, 13 } with the largest sum being 20.

    Now you are supposed to find the largest sum, together with the first and the last numbers of the maximum subsequence.

    Input

     

    Each input file contains one test case. Each case occupies two lines. The first line contains a positive integer K (<= 10000). The second line contains K numbers, separated by a space.

    Output

     

    For each test case, output in one line the largest sum, together with the first and the last numbers of the maximum subsequence. The numbers must be separated by one space, but there must be no extra space at the end of a line. In case that the maximum subsequence is not unique, output the one with the smallest indices i and j (as shown by the sample case). If all the K numbers are negative, then its maximum sum is defined to be 0, and you are supposed to output the first and the last numbers of the whole sequence.

    Sample Input

    10
    -10 1 2 3 4 -5 -23 3 7 -21

    Sample Output

     10 1 4

    Uploader

    lucy

    暴力就好了,这里是taozi的代码
    #include<bits/stdc++.h>
    using namespace std;
    int n,a,fi,sum,maxx,pre,maxi,maxj,flag;
    int main()
    {
        scanf("%d",&n);
        int a[10005];
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            if(a[i]>=0)
                flag=1;
        }
        for(int i=0;i<n;i++)
        {
            sum+=a[i];
            if(sum>maxx||sum==maxx&&maxx==0)maxx=sum,maxi=pre,maxj=i;
            if(sum<0)sum=0,pre=i+1;
        }
        if(!flag)
            printf("0 %d %d
    ",a[0],a[n-1]);
        else
            printf("%d %d %d
    ",maxx,a[maxi],a[maxj]);
        return 0;
    }

    1008

    Time Limit(Common/Java):2000MS/6000MS     Memory Limit:65536KByte
    Total Submit: 8            Accepted: 4

    Description

     

    给你n根火柴棍,你可以拼出多少个形如“A+B=C”的等式?等式中的A、B、C是用火柴棍拼出的整数(若该数非零,则最高位不能是0)。用火柴棍拼数字0-9的拼法如图所示:

     

    注意:

    1. 加号与等号各自需要两根火柴棍

    2. 如果A≠B,则A+B=C与B+A=C视为不同的等式(A、B、C>=0)

    3. n根火柴棍必须全部用上

     

    Input

     

    共一行,又一个整数n(n<=24)。

    Output

     

    共一行,表示能拼成的不同等式的数目。

    Sample Input

     

    14

    Sample Output

     2

    Hint

    2个等式为0+1=1和1+0=1。

    Uploader

    crq

    这个就是暴力每个字符需要几根火柴

    #include<stdio.h>
    int a[10]={6,2,5,5,4,5,6,3,7,6};
    int Fun(int n)
    {
        int i,j,sum=0;
        if(n==0)
        return 6;
        while(n)
        {
           sum+=a[n%10];
           n/=10;
        }
        return sum;
    }
    int main()
    {
        int i,j,k,n,sum;
        scanf("%d",&n);
        n-=4;sum=0;
        for(i=0;i<1000;i++) 
        for(j=0;j<1000;j++)
        {
          if(Fun(i)+Fun(j)+Fun(i+j)==n)
          {
                sum++;
          }
        }
        printf("%d
    ",sum);
        return 0;
    } 

    gld大佬的,预处理之后就可以加快了

    #include<iostream>
    using namespace std;
    int main()
    {
        int i,j,m,n,sum=0,a[1001]={6,2,5,5,4,5,6,3,7,6};
        cin>>n;
        for(i=10;i<=1000;i++)
        {
            m=i;
            while(m!=0)
            {
                a[i]=a[i]+a[m%10];
                m=m/10;
            }
        }
        n=n-4;
        if(n>0)
        for(i=1000;i>=0;i--)
        {
            for(j=0;j<=i;j++)
            {
                if(a[i]+a[j]+a[i-j]==n)
                {
                    sum++;
                }
            }
        }
        printf("%d",sum);
    }

    1009

    Time Limit(Common/Java):1000MS/3000MS     Memory Limit:65536KByte
    Total Submit: 5            Accepted: 3

    Description

     

    本题要求计算A/B,其中A是不超过1000位的正整数,B是1位正整数。你需要输出商数Q和余数R,使得A = B * Q + R成立。

    Input

     

    输入在1行中依次给出A和B,中间以1空格分隔。

    Output

     

    在1行中依次输出Q和R,中间以1空格分隔。

    Sample Input

    123456789050987654321 7

    Sample Output

     17636684150141093474 3

    Uploader

    crq

    模拟下大数

     

    #include<iostream>
    #include<string>
    using namespace std;
    int main(){
        string str,ans;
        int n,d = 0; 
        cin>> str>> n;
        for(int i = 0; i <= str.size()-1; i++){
            int current = d * 10 + (str[i]-'0');
            ans+=(current/n+'0');
            d=current % n;
        }
        for(int i=(ans[0] == '0'&&ans.size()!=1)?1:0;i<ans.size();i++)
            cout << ans[i];
        cout << " " << d;
        return 0;
    }

     

    1010

    Time Limit(Common/Java):1000MS/3000MS     Memory Limit:65536KByte
    Total Submit: 8            Accepted: 7

    Description

     

    给定操作数,对其进行二进制运算。

    二进制运算主要有:

    &:与运算,二元运算符,当两个位都为1时结果才为1,其他为0

    |:或运算,二元运算符,当两个为都为0时结果才为0,其他为1

    ~:非运算,一元运算符,当该位为0时结果为1,否则为0

    ^:异或运算,二元运算符,当两个位不同时结果为1,否则为0

    Input

     

    输入有多组,第一行数据组数T,接下来有T行,每行一个运算,可以为:

    & a b

    | a b

    ~ a

    ^ a b

    运算符和操作数、操作数和操作数之间有空格隔开, a和b均为整数,绝对值不大于100,系统int占32bits。

     

    Output

     

    输出结果

    Sample Input

    2
    & 1 2
    ~ 1

    Sample Output

    0
    -2

    Uploader

    crq

    真的签到题

    #include <stdio.h>
    int main()
    {
        int t;
        scanf("%d",&t);
        while(t--)
        {
            char c;
            int a,b;
            getchar();
            scanf("%c",&c);
            if(c=='&')
            {
                scanf("%d%d",&a,&b);
                printf("%d
    ",a&b);
            }
            else if(c=='|')
            {
                scanf("%d%d",&a,&b);
                printf("%d
    ",a|b);
            }
            else if(c=='^')
            {
                scanf("%d%d",&a,&b);
                printf("%d
    ",a^b);
            }
            else
            {
                scanf("%d",&a);
                printf("%d
    ",~a);
            }
        }
        return 0;
    }

    1011

    Time Limit(Common/Java):1000MS/3000MS     Memory Limit:65536KByte
    Total Submit: 10            Accepted: 5

    Description

     

      世界上最遥远的距离
      不是生与死
      而是我就站在你面前
      你却不知道我爱你

      世界上最遥远的距离
      不是我就站在你面前你却不知道我爱你
      而是明明知道彼此相爱
      却不能在一起

      世界上最遥远的距离
      不是明明知道彼此相爱却不能在一起
      而是相约好了私奔的时间
      我穿越到了未来 你却回去了古代

        ----摘自《小Q失恋日记 》第117卷513页


      当小Q使出浑身解数,终于赢得HR女神芳心的时候,却出现了一个意外情况,那就是白富美HR的妈妈并不同意他们交往,当听说小Q只是一个码农,特别是听说小Q曾经参加过资本主义国家发起的SM/ICPC比赛的时候,更是坚决反对!
      爱情是伟大的,但是得不到亲人祝福的爱情却备受折磨,小Q和HR相约在腾讯第二届编程马拉松大赛进行到第5天的时候(即2013年3月24日),一起“向前穿越D天,然后开启幸福新生活”。
      其勇气可谓令人赞叹,但可怜的小Q却总是备受折磨----小Q理解的“向前穿越”是朝着未来的方向,而女友HR理解的“向前穿越”却是朝着古代的方向!
      假设已知现在的日期和穿越的天数D,你能计算出小Q和女友各自到达的年代吗?

    Input

     

    输入首先包含一个整数N,表示有N组测试用例;
    接下来N行是N组数据,每一行包含一个正整数D(0<=D<=10,0000),D表示向前穿越的天数。

    Output

     

    请计算并输出小Q和女友分别到达的日期,日期格式为YYYY/MM/DD,两个日期中间用一个空格隔开,每组数据占一行,具体输出格式请参见样例。

    Sample Input

    2
    6
    30

    Sample Output

    2013/03/30 2013/03/18
    2013/04/23 2013/02/22

    Uploader

    shfs

    D并不大,可以去暴力出来的

     

    #include <stdio.h>
    
    int a[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
    const int Y=2013,M=3,D=24;
    void deal1(int k)
    {    int y = Y,m = M,d = D;
        while(k--)
        {
            if(y%400==0||y%4==0&&y%100!=0)
            a[2]=29;
            else  a[2]=28;
            d--;
            if(d<=0)
            {
                m--;
                if(m<=0)
                {
                    m = 12;
                    y--;
                }
                d = a[m];
            }
        }
        printf("%04d/%02d/%02d",y,m,d);
    }
    void deal2(int k)
    {
        int y = Y,m = M,d = D;
        while(k--)
        {
            if(y%400==0||y%4==0&&y%100!=0)
            a[2] = 29;
            else  a[2]=28;
            d++;
            if(d>a[m])
            {
                m++;
                if(m>12)
                {
                    m=1;
                    y++;
                }
                d = 1;
            }
        }
        printf("%04d/%02d/%02d ",y,m,d);
    }
    
    int main()
    {
        int n,m;
        scanf("%d",&n);
        while(n--)
        {
            scanf("%d",&m);
            deal2(m);
            deal1(m);
            printf("
    ");
        }
        return 0;
    }

     

    1012

    Time Limit(Common/Java):5000MS/15000MS     Memory Limit:65536KByte
    Total Submit: 5            Accepted: 2

    Description

     

    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

    Uploader

    crq

    这种TOJ难度很高的题目其实就是模拟啊,但是可以说写一次是非常麻烦了

    #include<stdio.h>
    #include<string.h>
    char s[128];
    int la(int k)
    {
        while(k--)
        {
            if(s[k]>='0'&&s[k]<'9'||s[k]>='a'&&s[k]<'z'||s[k]>='A'&&s[k]<'Z')
            {
                s[k]++;
                return 0;
            }
            else if(s[k]=='9')
            {
                s[k]='0';
                if(la(k))return 1;
                return 0;
            }
            else if(s[k]=='z')
            {
                s[k]='a';
                if(la(k))return 1;
                return 0;
            }
            else if(s[k]=='Z')
            {
                s[k]='A';
                if(la(k))return 1;
                return 0;
            }
        }
        return 1;
    }
    int main()
    {
        int T;
        scanf("%d",&T);
        while(T--)
        {
            int n;
            scanf("%s%d",s,&n);
            while(n--)
            {
                int l=strlen(s),i,f=la(l);
                if(f==1)
                {
                    for(i=0; i<l; i++)
                        if(s[i]=='0'||s[i]=='a'||s[i]=='A')break;
                    if(i<l)
                    {
                        s[l+1]=0;
                        for(;l>i;l--)
                            s[l]=s[l-1];
                        if(s[i]=='0')s[i]++;
                    }
                    else s[l-1]++;
                }
                puts(s);
            }
            putchar(10);
        }
        return 0;
    }

     

  • 相关阅读:
    Docker+Jenkins更换国内插件源
    招聘java工程师
    Apache seaTunnel 数据集成平台
    DBeaver连接MySQL问题的解决
    iphone的mov文件复制到电脑的方法
    IDEA中RestfulToolkit插件的安装及使用
    lwm2m 的notify 的机制
    ALI云接入学习
    CAT1 UIS8910模组对接阿里云平台
    任务的堆栈究竟有何魔力
  • 原文地址:https://www.cnblogs.com/BobHuang/p/8689902.html
Copyright © 2011-2022 走看看