题干:

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';}
}

【CodeForces - 1051A】Vasya And Password (构造,水题)相关推荐

  1. Educational Codeforces Round 7 B. The Time 水题

    B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...

  2. 【CodeForces - 1A】Theatre Square(水题,几何)(CODEFORCES,梦的开始)

    题干: Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters ...

  3. C - Internet Address CodeForces - 245B(有些思维的水题)

    Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote ...

  4. Codeforces Round #300 A. Cutting Banner 水题

    A. Cutting Banner Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/538/pro ...

  5. CodeForces - 1263A Sweet Problem(思维,水题)

    题目链接:点击查看 题目大意:给出三种颜色的糖果,分别表示为r,g,b,现在Tanya每天可以吃两个不同颜色的糖果,问最多可以吃多少天 题目分析:大水题一个,但自己真的蠢,一开始思路混乱,写了一大堆乱 ...

  6. 【CodeForces - 215A】Bicycle Chain (水题)

    题干: Vasya's bicycle chain drive consists of two parts: n stars are attached to the pedal axle, m sta ...

  7. 【CodeForces - 1038A 】Equality (思维水题,预处理字符串)

    题干: You are given a string ss of length nn, which consists only of the first kk letters of the Latin ...

  8. 【CodeForces - 707B】Bakery(思维水题)

    Bakery Descriptions 玛莎想在从1到n的n个城市中开一家自己的面包店,在其中一个城市烘焙松饼. 为了在她的面包房烘焙松饼,玛莎需要从一些储存的地方建立面粉供应.只有k个仓库,位于不同 ...

  9. CodeForces - 22A Second Order Statistics【水题】

    题目链接:https://codeforces.com/contest/22/problem/A #include <iostream> #include <vector> # ...

  10. Educational Codeforces Round 10 C. Foe Pairs 水题

    C. Foe Pairs 题目连接: http://www.codeforces.com/contest/652/problem/C Description You are given a permu ...

最新文章

  1. 清华硕士爆料:这些才是机器学习必备的数学基础
  2. springboot oauth2 fetch 关于跨域请求的问题
  3. maven设置jdk版本(全局设置和工程设置)
  4. 结合scipy.linalg在Python中使用线性系统
  5. select时尽可能少使用as对性能很有好处
  6. 用户界面草图设计工具-工具包和资源
  7. pager-taglib 使用说明
  8. win7一直显示正在关机_windows8.1和windows7哪个好_win8.1好还是win7好用
  9. VBA实战技巧精粹013:宏代码保存工作簿的3种方法
  10. mac地址查 计算机名字,怎么看mac地址-教你通过MAC地址查询设备的厂商名称
  11. emu8086——buf 缓冲区的字节数据排序算法程序
  12. USB转串口芯片CH340
  13. IDEA-快捷键noob
  14. 【unity3D弹跳的小球游戏制作】
  15. Rstudio永久修改当前工作路径
  16. CloudDrive — 将阿里云盘变成电脑本地磁盘,网盘挂载映射为本地磁盘!
  17. 理解SparkSteaming窗口函数操作window()
  18. 微软Office 2013:会受企业待见的最佳新功能
  19. 计算机科学方向的会议或期刊,计算机顶会和顶刊_计算机顶会_顶会
  20. CNCF宣布TUF项目正式毕业

热门文章

  1. [Leetcode][第114题][JAVA][二叉树展开为链表][递归][迭代]
  2. [Leedcode][第215题][JAVA][数组中的第K个最大元素][快排][优先队列]
  3. [Leedcode][JAVA][第876题][快慢指针]
  4. xml生成2维码_MyBatis(2)之MyBatis-Generator最佳实践
  5. 软件测试之逻辑覆盖测试理论总结(白话文)
  6. 自动打包linux,Linux环境下Springboot自动打包发布功能
  7. 计算机找不到管理无线网络,电脑wifi密码忘了 并且找不到管理无线网络该怎么处理?...
  8. php 简析对象,PHP白盒审计工具RIPS源码简析
  9. asterisk for mipsel
  10. wince中重启网卡