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 ...
随机推荐
- Linux学习笔记之Linux添加/删除用户和用户组
本文总结了Linux添加或者删除用户和用户组时常用的一些命令和参数. 1.建用户: adduser phpq //新建phpq用户 passwd phpq //给phpq用户设置密码 2.建工作组 g ...
- 基于MFC开发的指纹识别系统.
MFC-FingerPrint 基于MFC开发的指纹识别系统. 效果图如下: 在第12步特征入库中,会对当前指纹的mdl数据与databases中所有的mdl进行对比,然后返回识别结果. 一.载入图像 ...
- day10函数,函数的使用,函数的分类,函数的返回值
函数 # ***** # 函数:完成 特定 功能的代码块,作为一个整体,对其进行特定的命名,该名字就代表函数 # -- 现实中:很多问题要通过一些工具进行处理 => 可以将工具提前生产出来并命名 ...
- code回顾
Linq return Content("<script>alert('你想说的话');javascript:history.go(-1);</script>&quo ...
- List集合流处理类型小结
本文为博主原创,未经允许不得转载 对应实体类 import lombok.Getter; import lombok.Setter; @Getter @Setter public class Stud ...
- PageRank算法实现
基本原理 在互联网上,如果一个网页被很多其他网页所链接,说明它受到普遍的承认和信赖,那么它的排名就高.这就是PageRank的核心思想. 引用来自<数学之美>的简单例子: 网页Y的排名应该 ...
- static属性和方法
static属性作为公共属性,可以通过类名称直接调用. static属性可以在没有实例化对象时使用. 非static属性必须在实例化对象产生后才可以使用. static方法也可以在没有实例化对象时由类 ...
- selenium java maven testNg环境搭建
maven获取jar的xml地址:http://mvnrepository.com 步骤一安装jdk(略) 步骤二 安装eclipse(略) 步骤三 安装testNG 步骤四 maven安装 步骤三 ...
- vuex的学习和理解
初识Vuex: vuex是 vue官方推荐的一个状态管理器,也是vue专用的一个插件.当我们遇到很多状态改变时,组件之间的通信就会变得复杂,这时候vuex的强大就体现出来了. Vuex 应用的核心就是 ...
- 《R语言入门与实践》第二章:R包和帮助文档
这一章讲了两方面的内容,如何使用 R 包和帮助文档. R包 下载 R 包 命令: install.packages("<nameofpackage>") R 会话中启用 ...