【CodeForces - 1051A】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 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

Input

2
abcDCE
htQw27

Output

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).

解题报告:

 

错误代码1:

#include<bits/stdc++.h>
#define ll long long
using namespace std;
string s;
int main() 
{int t;cin>>t;while(t--) {cin>>s;int low=-1,upp=-1,dig=-1;int l=0,u=0,d=0;for(int i = 0; i<s.length(); i++) {if(s[i] >= 'a' && s[i] <= 'z') low = i,l++;if(s[i] >= 'A' && s[i] <= 'Z') upp = i,u++;if(s[i] >= '1' && s[i] <= '9') dig = i,d++; }if(low == -1) {if(u>=2) s[upp] = 'a';else s[dig] = 'a';}if(upp == -1) {if(l>=2) s[low] = 'A';else s[dig] = 'A';}if(dig == -1) {if(l>=2) s[low] = '1';else s[upp] = '1';}cout << s << endl;}return 0;
}

1wa在了思路上(代码如上),这样写是不对的,因为有可能upp和dig都等于-1,所以都需要low进行更新,举个例子“aaa”,就会发现样例结果是错的。

2wa在了判断数字,,,应该是s[i]>='0' 为甚要写>=‘1’    怎么想的???

AC代码:

#include<bits/stdc++.h>
#define ll long long
using namespace std;
char s[505];
int l[505],u[505],d[505];
int cnt1,cnt2,cnt3;
int main() 
{int t;cin>>t;getchar();while(t--) {gets(s);int len = strlen(s);int low=-1,upp=-1,dig=-1;cnt1=cnt2=cnt3=0;for(int i = 1; i<505; i++) l[i]=u[i]=d[i]=0;for(int i = 0; i<len; i++) {if(s[i] >= 'a' && s[i] <= 'z') low = i,l[++cnt1] = i;if(s[i] >= 'A' && s[i] <= 'Z') upp = i,u[++cnt2] = i;if(s[i] >= '0' && s[i] <= '9') dig = i,d[++cnt3] = i; }if(low == -1) {if(cnt2 >= 2) s[u[cnt2--]]='a';else s[d[cnt3--]] = 'a';}if(upp == -1) {if(cnt1>=2) s[l[cnt1--]] = 'A';else s[d[cnt3--]] = 'A';}if(dig == -1) {if(cnt1>=2) s[l[cnt1--]] = '1';else s[u[cnt2--]] = '1';}cout << s << endl;}return 0;
}

发现了别人的优秀代码:嗯还是有很多可以学习的。。要善于运用vector等容器啊

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
template <typename T>
using ost = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define forn(i,n) for(int i=0; i<int(n); ++i)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define ff first
#define ss secondint main() {ios::sync_with_stdio(false);int T;cin >> T;while (T--) {string s;cin >> s;bool lo=0, hi=0, dig=0;vi x;int n=s.size();for (int i=0; i<n; i++) {if (isdigit(s[i])) {if (dig) x.pb(i);dig=1;}else if (islower(s[i])) {if (lo) x.pb(i);lo=1;}else {if (hi) x.pb(i);hi=1;}}if (!dig) {s[x.back()]='1';x.pop_back();}if (!lo) {s[x.back()]='a';x.pop_back();}if (!hi) {s[x.back()]='A';x.pop_back();}cout << s << '\n';}
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441581.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

html5引擎笔试题,最新!HTML5经典面试题型(附答案)

HTML已更新至HTML5&#xff0c;那么HTML5的测试题您也应该知道&#xff0c;这篇文章可以作为您的参考。1.doctype有什么作用呢&#xff1f;如何区分其混合模式和标准模式&#xff1f;所有这些都意味着什么&#xff1f;Doctype的作用是告诉浏览器使用HTML规范的哪个版本来渲染文…

【CodeForces - 1051B】Relatively Prime Pairs (构造,思维,素数,水题)

题干&#xff1a; You are given a set of all integers from ll to rr inclusive, l<rl<r, (r−l1)≤3⋅105(r−l1)≤3⋅105and (r−l)(r−l) is always odd. You want to split these numbers into exactly r−l12r−l12 pairs in such a way that for each pair (i,…

html 弹出加载页面,magnific popup:将整个html页面加载到弹出窗口中

我想用弹出的插件在弹出窗口中加载一个完整的html页面。如果我尝试&#xff1a;Edit images$(#edit-images-btn).magnificPopup({type: ajax});它产生了这个&#xff1a;这在图形上非常符合我的要求&#xff0c;但问题是的内容直接插入到dom中&#xff0c;而不是放在保护性的if…

【CodeForces - 1042A】Benches (优先队列,思维模拟,maxmin问题)

题干&#xff1a; There are nn benches in the Berland Central park. It is known that aiai people are currently sitting on the ii-th bench. Another mm people are coming to the park and each of them is going to have a seat on some bench out of nn available. …

网页html 图片横向摆放,css实现多张图片横向居中显示的方法

先讲一下实现的步骤&#xff1a;最终效果2. 代码实现HTML部分分类小贴士CSS部分.main{width:100%;margin-top:40px;}.main .tag{margin:0 auto;width:200px;font-size:18px;border-bottom:1px solid #878787;text-align:center;margin-bottom:20px;}.main .images{margin:0 aut…

【CodeForces - 1042B】Vitamins(去重方法,二进制或stlmap,水题)

题干&#xff1a; Berland shop sells nn kinds of juices. Each juice has its price cici. Each juice includes some set of vitamins in it. There are three types of vitamins: vitamin "A", vitamin "B" and vitamin "C". Each juice ca…

android 中断处理流程,Android P的native crash处理流程

一、概述Android系统有监控程序异常退出的机制&#xff0c;这便是本文要讲述得debuggerd守护进程。当发生native crash或者主动调用debuggerd时&#xff0c;会输出进程相关的状态信息到文件或者控制台。输出的debuggerd数据 保存在文件/data/tombstones/tombstone_XX&#xff0…

数论中的无数公式 总结

斯特林公式是一条用来取n阶乘近似值的数学公式。一般来说&#xff0c;当n很大的时候&#xff0c;n阶乘的计算量十分大&#xff0c;所以斯特灵公式十分好用&#xff0c;而且&#xff0c;即使在 n很小的时候&#xff0c;斯特灵公式的取值已经十分准确。 公式为&#xff1a; 以下…

计算机怎样连接网络适配器,win10 本地连接共享internet时, 会将承载网络适配器IP设置成192.168.137.1但不成功...

您好&#xff0c;谢谢您&#xff01;我后来参考了http://www.ishanarora.com/2009/07/29/windows-7-as-a-wireless-access-point/ 中的 Jenny提到的方案COMPLETE SOLUTION:### create virtual vwlan hosted port, set AP ssid to advertise, and its password- [cmd] netsh wla…

【POJ - 1001 】Exponentiation (Java大数,高精度)

题干&#xff1a; Problems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the national debt is a taxing experience for many computer systems. This problem requires that you write…

用计算机唱出惊雷,除了《惊雷》还有多少喊麦神曲?这十首神作你一定听过!...

一首《惊雷》可以说是火遍了大江南北&#xff0c;一时间风头无二。而这两天杨坤对《惊雷》的diss、惊雷原唱六道的回应更是成为全网热搜&#xff0c;这也让以《惊雷》为首的“喊麦文化”再次进入了公众的视线。事实上除了《惊雷》&#xff0c;还有不少脍炙人口的喊麦神曲&#…

ACM算法 -- 数论 -- 开灯关灯问题(数论,整数分解,因子个数,公式推导)

有编号1~100个灯泡&#xff0c;起初所有的灯都是灭的。有100个同学来按灯泡开关&#xff0c;如果灯是亮的&#xff0c;那么按过开关之后&#xff0c;灯会灭掉。如果灯是灭的&#xff0c;按过开关之后灯会亮。 现在开始按开关。 第1个同学&#xff0c;把所有的灯泡开关都按一次…

计算机编程是考研什么专业,程序员考研该不该继续选择计算机专业

首先&#xff0c;近些年来确实有不少程序员会选择通过读研来突破自身的岗位发展瓶颈&#xff0c;大部分程序员在读研后也都获得了岗位升级&#xff0c;还有一部分程序员会继续读博&#xff0c;从而进入到科研和教育领域发展。从当前的技术发展趋势和人才需求趋势来看&#xff0…

【牛客 - 185D】星光晚餐(数论,结论,思维,模型)

题干&#xff1a; Johnson和Nancy要在星光下吃晚餐。这是一件很浪漫的事情。 为了增加星光晚餐那浪漫的氛围&#xff0c;他拿出了一个神奇的魔法棒&#xff0c;并且可以按照一定的规则&#xff0c;改变天上星星的亮暗。 Johnson想考考Nancy&#xff0c;在他挥动魔法棒后&#x…

vue 模板 html 表达式,Vue 模板template、指令directive、修饰符

模板 templatetemplate的三种写法写法一&#xff1a;Vue完整版&#xff0c;写在HTML里//html{{n}}1//vuenew Vue({el: #xxx,data(){return{n:0}},methods:{add(){}}})复制代码写法二&#xff1a;Vue完整版&#xff0c;写在选项里//html//vuenew Vue({template: {{n}}1,data(){r…

黄冈学计算机的学校怎么样,广元市黄冈学校怎么样、好不好

问&#xff1a;广元市黄冈学校怎么样、好不好?答&#xff1a;办学四年多来&#xff0c;学校在上级主管部门考核中一直名列前茅&#xff0c;得到广大学生家长的认可&#xff0c;多次受到上级表彰&#xff0c;被评为“民办教育先进集体”&#xff0c;学校环境优美&#xff0c;是…

【 HDU - 1215 】七夕节(数论,约数和公式)

题干&#xff1a; 七夕节那天,月老来到数字王国,他在城门上贴了一张告示,并且和数字王国的人们说:"你们想知道你们的另一半是谁吗?那就按照告示上的方法去找吧!" 人们纷纷来到告示前,都想知道谁才是自己的另一半.告示如下: 数字N的因子就是所有比N小又能被N整除的…

计算机专业小三门要求,最新小三门选科要求有啥变化?附对比表

原标题&#xff1a;最新小三门选科要求有啥变化&#xff1f;附对比表刚刚&#xff0c;上海市教育考试院公布了2020年拟在沪招生普通高校、军队院校本科专业选考科目要求&#xff0c;让我们今年的选科范围有哪些变化&#xff1f;说明&#xff1a;1 选考范围为不限&#xff0c;说…

【51Nod - 1215 】数组的宽度 (单调栈 或 分治 或 单调队列,算贡献,需去重)

题干&#xff1a; N个整数组成的数组&#xff0c;定义子数组aii..ajj的宽度为&#xff1a;max(ai..aj) - min(ai..aj)&#xff0c;求所有子数组的宽度和。 Input 第1行&#xff1a;1个数N&#xff0c;表示数组的长度。(1 < N < 50000) 第2 - N 1行&#xff1a;每行1…

云昆明理工大学 计算机复试,2012年昆明理工大学计算机考研复试试题(回忆版)...

2012年昆明理工大学计算机考研复试试题(年昆明理工大学计算机考研复试试题(回忆版)回忆版)本试题由http://doc.xuehai.net网友kenden23提供笔试C(总共30分)一、40题选择题(20分)1.派生类调用构造函数时&#xff0c;基类的构造函数先调用&#xff1b;2. int a1,b1,c1,d1,e1;if((…