Educational Codeforces Round 51 (Rated for Div. 2) A. Vasya And Password

A. Vasya And Password

Vasya came up with a password to register for EatForces — a string ss. The password in EatForces should be a string, consisting of lowercase and uppercase Latin letters and digits.

But since EatForces takes care of the security of its users, user passwords must contain at least one digit, at least one uppercase Latin letter and at least one lowercase Latin letter. For example, the passwords "abaCABA12", "Z7q" and "3R24m" are valid, and the passwords "qwerty", "qwerty12345" and "Password" are not.

A substring of string ss is a string x=slsl+1…sl+len−1(1≤l≤|s|,0≤len≤|s|−l+1)x=slsl+1…sl+len−1(1≤l≤|s|,0≤len≤|s|−l+1). lenlen is the length of the substring. Note that the empty string is also considered a substring of ss, it has the length 00.

Vasya's password, however, may come too weak for the security settings of EatForces. He likes his password, so he wants to replace some its substring with another string of the same length in order to satisfy the above conditions. This operation should be performed exactlyonce, and the chosen string should have the minimal possible length.

Note that the length of ss should not change after the replacement of the substring, and the string itself should contain only lowercase and uppercase Latin letters and digits.

Input

The first line contains a single integer TT (1≤T≤1001≤T≤100) — the number of testcases.

Each of the next TT lines contains the initial password s (3≤|s|≤100)s (3≤|s|≤100), consisting of lowercase and uppercase Latin letters and digits.

Only T=1T=1 is allowed for hacks.

Output

For each testcase print a renewed password, which corresponds to given conditions.

The length of the replaced substring is calculated as following: write down all the changed positions. If there are none, then the length is 00. Otherwise the length is the difference between the first and the last changed position plus one. For example, the length of the changed substring between the passwords "abcdef" →→ "a7cdEf" is 44, because the changed positions are 22 and 55, thus (5−2)+1=4(5−2)+1=4.

It is guaranteed that such a password always exists.

If there are several suitable passwords — output any of them.

Example

input

Copy

2
abcDCE
htQw27

output

Copy

abcD4E
htQw27

题意:给你一个字符串,必须包含大写,小写字母,数字三种,如果不满足,需要你修改,所更改的区间必须最小。

思路:仔细推一下会发现只有两种情况

1. 三个条件,只有一个不满足,此时字符串里已有两种,所以找到出现多的一种改掉就可以,比如a99,缺少大写字母,只能改9,不能动a。

2. 三个条件,有两个不满足,此时字符串里只有一种,非常简单,直接s[0]与s[1]替换成另外两种即可。

不可能会有三者都不满足的情况。

#include <bits/stdc++.h>
#define ll long long
using namespace std;
char s[110];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%s",s);
        int len=strlen(s);
        int x1,x2,x3;
        x1=x2=x3=0;
        for(int i=0;i<len;i++)
        {
            if(s[i]>='a'&&s[i]<='z')x1++;  //统计每种类型出现了多少次
            if(s[i]>='A'&&s[i]<='Z')x2++;
            if(s[i]>='0'&&s[i]<='9')x3++;
        }
        if((x1==0)&&(x2>=1)&&(x3>=1))
        {
            if(x2>x3)
            {
                for(int i=0;i<len;i++)
                {
                    if(s[i]>='A'&&s[i]<='Z')
                    {
                        s[i]='a';
                        break;
                    }
                }
            }
            else
            {
                for(int i=0;i<len;i++)
                {
                    if(s[i]>='0'&&s[i]<='9')
                    {
                        s[i]='a';
                        break;
                    }
                }
            }
        }
        else if((x1>=1)&&(x2==0)&&(x3>=1))
        {
            if(x1>x3)
            {
                for(int i=0;i<len;i++)
                {
                    if(s[i]>='a'&&s[i]<='z')
                    {
                        s[i]='A';
                        break;
                    }
                }
            }
            else
            {
                for(int i=0;i<len;i++)
                {
                    if(s[i]>='0'&&s[i]<='9')
                    {
                        s[i]='A';
                        break;
                    }
                }
            }
        }
        else if((x1>=1)&&(x2>=1)&&(x3==0))
        {
            if(x1>x2)
            {
                for(int i=0;i<len;i++)
                {
                    if(s[i]>='a'&&s[i]<='z')
                    {
                        s[i]='9';
                        break;
                    }
                }
            }
            else
            {
                for(int i=0;i<len;i++)
                {
                    if(s[i]>='A'&&s[i]<='Z')
                    {
                        s[i]='9';
                        break;
                    }
                }
            }
        }
        else if((x1==0)&&(x2==0)&&(x3>=1))
        {
            s[0]='a';
            s[1]='A';
        }
        else if((x1==0)&&(x2>=1)&&(x3==0))
        {
            s[0]='a';
            s[1]='9';
        }
        else if((x1>=1)&&(x2==0)&&(x3==0))
        {
            s[0]='A';
            s[1]='9';
        }
        printf("%s\n",s);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/s540239976/article/details/83211450