Vasya And Password(CodeForces - 1051A)
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 exactly once, 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
2
abcDCE
htQw27
abcD4E
htQw27
Note
In the first example Vasya's password lacks a digit, he replaces substring "C" with "4" and gets password "abcD4E". That means, he changed the substring of length 1.
In the second example Vasya's password is ok from the beginning, and nothing has to be changed. That is the same as replacing the empty substring with another empty substring (length 0).
题解:虽然是A类题,但是还是没能一遍过(哭.....,代码比较low,写给自己体会。
代码如下:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define swap(a,b) (a=a+b,b=a-b,a=a-b)
#define maxn 320007
#define N 100000000
#define INF 0x3f3f3f3f
#define mod 1000000009
#define e 2.718281828459045
#define eps 1.0e18
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define read(x) scanf("%d",&x)
#define put(x) printf("%d\n",x)
#define memset(x,y) memset(x,y,sizeof(x))
#define Debug(x) cout<<x<<" "<<endl
#define lson i << 1,l,m
#define rson i << 1 | 1,m + 1,r
#define ll long long
//std::ios::sync_with_stdio(false);
//cin.tie(NULL);
using namespace std; int d[],x[],s[];
char a[];
int main()
{
int n;
cin>>n;
for(int i=;i<n;i++)
{
memset(a,);
memset(d,);
memset(x,);
memset(s,);
cin>>a;
int l=strlen(a);
int ansd=,ansx=,anss=;
int y=-,yy=-,yyy=-;
for(int j=;j<l;j++)
{
if(a[j]>='a'&&a[j]<='z')
{
y=j;
x[ansx++]=j;
}
if(a[j]>='A'&&a[j]<='Z')
{
yy=j;
d[ansd++]=j;
}
if(a[j]>=''&&a[j]<='')
{
yyy=j;
s[anss++]=j;
}
}
if(y==-)
{
if(ansd>=)
a[d[--ansd]]='a';
else
a[s[--anss]]='a';
}
if(yy==-)
{
if(ansx>=)
a[x[--ansx]]='A';
else
a[s[--anss]]='A';
}
if(yyy==-)
{
if(ansx>=)
a[x[--ansx]]='';
else
a[d[--ansd]]='';
}
cout<<a<<endl;
}
return ;
}
Vasya And Password(CodeForces - 1051A)的更多相关文章
- PAT 甲级 1035 Password (20 分)
1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for th ...
- 1035 Password (20 分)
1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for th ...
- (CodeForces - 5C)Longest Regular Bracket Sequence(dp+栈)(最长连续括号模板)
(CodeForces - 5C)Longest Regular Bracket Sequence time limit per test:2 seconds memory limit per tes ...
- pat 1035 Password(20 分)
1035 Password(20 分) To prepare for PAT, the judge sometimes has to generate random passwords for the ...
- Sorted Adjacent Differences(CodeForces - 1339B)【思维+贪心】
B - Sorted Adjacent Differences(CodeForces - 1339B) 题目链接 算法 思维+贪心 时间复杂度O(nlogn) 1.这道题的题意主要就是让你对一个数组进 ...
- Codeforces 1058 D. Vasya and Triangle(分解因子)
题目:http://codeforces.com/contest/1058/problem/D 题意:有一个大小为N*M的矩阵内,构造一个三角形,使面积为(n*m)/k.若存在输出三个顶点(整数). ...
- Codeforces Round #394 (Div. 2) C. Dasha and Password(简单DP)
C. Dasha and Password time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- (CodeForces 558C) CodeForces 558C
题目链接:http://codeforces.com/problemset/problem/558/C 题意:给出n个数,让你通过下面两种操作,把它们转换为同一个数.求最少的操作数. 1.ai = a ...
- Vasya and String(尺取法)
Vasya and String time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
随机推荐
- KVO的使用三:基于runtime实现KVO
苹果的KVO原理通过isa-swizzling技术实现,本质实现逻辑是在runtime时添加一个子类,重写set方法进行操作,现在我们也基于runtime来实现一个KVO. 首先新建一个Person类 ...
- Python中 sys.argv[]的用法简明解释
sys.argv[]就是一个从程序外部获取参数的桥梁,这个“外部”很关键.因为我们从外部取得的参数可以是多个,所以获得的是一个列表(list),也就是说sys.argv其实可以看作是一个列表,所以才能 ...
- 如何实现win7系统多用户同时远程登录
使用Win7系统的时候,不同的管理账号远程登录桌面时,会把远程登录的人给记下来.如何设置Win7让两个账号的两会话同时存在,且相互之间不冲突. 方法/步骤 第一步:创建需要远程的两个用户账号. ...
- idea提交git报错Push rejected: Push to origin/master was rejected
参考https://blog.csdn.net/u012934325/article/details/71023241
- Ubuntu: 安装自带的中文输入法
1. 在终端安装输入法软件包 在终端输入 sudo apt-get install ibus-pinyin 2. 启用输入法 打开设置 找到Region&Language 找到Input So ...
- aop(execution()表达式)
execution(* com.tp.soft.service..*.*(..)) 整个表达式可以分为五个部分: 1.execution(): 表达式主体. 2.第一个*号:表示返回类型,*号表示所有 ...
- SSH应用实战——安全防护(fail2ban)
ssh 安全配置 端口 ssh随机端口范围在 27000-30000,可以手动修改也要改在这个范围内,建议定时修改端口. 密码 登陆密码应包含大小写.数字.特殊字符等 10 位以上,建议定期修改密码. ...
- redis -memcahe
tomcat自动化集成 https://blog.51cto.com/ellenv/1932817 Redis与Memcache对比:1.Memcache是一个分布式的内存对象缓存系统而redis是可 ...
- RobotFramework自动化测试框架-Selenium Web自动化(-)-Open Browser和Close Browser
Selenium出来已经有很多年了,从最初的Selenium1到后来的Selenium2,也变得越来越成熟,而且也已经被很多公司广泛使用.Selenium发展的过程中,分了很多模块,这里我们主要介绍W ...
- python 【pandas】账号、银行卡号、身份证号导出文件后以科学计数法显示问题解决
问题描述:excel表中的一些数据会以文本格式格式保存,例如一些较长的编号.银行账号.身份证号等,再python中导出文件后,会发现数据以科学计数法显示,影响后续使用. data2_3.to_exce ...