PAT甲级1035 Password

题目:
为了PAT做准备,法官有时必须为用户生成随机密码。问题是总是存在一些令人混淆的密码,因为很难区分1(一)和l(小写L),或0(零)和O(大写o)。一种解决方案是将1(一)替换为@0(零)替换为%l替换为LO替换为o。现在,你的工作是编写一个程序来检查由法官生成的帐户,并帮助该法官修改令人困惑的密码。
输入格式:
每个输入文件都包含一个测试用例。每个情况下包含一个正整数N(≤1000),后面是N行帐户。每个帐户由一个用户名和一个密码组成,它们都是不超过10个字符的字符串,没有空格。
输出格式:
对于每个测试用例,首先打印已修改的帐户数M,然后在以下M行打印修改后的帐户信息,即用户名和相应的修改密码。帐户的打印顺序必须与读取帐户的打印顺序相同。如果没有修改任何帐户,则按一行There are N accounts and no account is modified,并且没有修改任何帐户,其中N为帐户总数。但是,如果N为1,则必须打印There is 1 account and no account is modified
输入样例1:

3
Team000002 Rlsp0dfa
Team000003 perfectpwd
Team000001 R1spOdfa

输出样例1:

2
Team000002 RLsp%dfa
Team000001 R@spodfa

输入样例2:

1
team110 abcdefg332

输出样例2:

There is 1 account and no account is modified

输入样例3:

2
team110 abcdefg222
team220 abcdefg333

输出样例3:

There are 2 accounts and no account is modified

AC代码:

#include<iostream>

using namespace std;

const int maxn=1010;

struct user{
	char name[15];
	char password[15];
	int tag=0;
}us[maxn];

int main(){
	int n;
	cin>>n;
	int i,modified=0,j;
	for(i=0;i<n;i++){
		cin>>us[i].name>>us[i].password;
		for(j=0;us[i].password[j]!='\0';j++){
			if(us[i].password[j]=='1'){
				us[i].password[j]='@';
				us[i].tag=1;
			}
			if(us[i].password[j]=='0'){
				us[i].password[j]='%';
				us[i].tag=1;
			}
			if(us[i].password[j]=='l'){
				us[i].password[j]='L';
				us[i].tag=1;
			}
			if(us[i].password[j]=='O'){
				us[i].password[j]='o';
				us[i].tag=1;
			}
		}
		if(us[i].tag==1)
		modified++;
	}
	if(modified==0){
		if(n>1)
		cout<<"There are "<<n<<" accounts and no account is modified";
		else
		cout<<"There is "<<n<<" account and no account is modified";
	}
	else{
		cout<<modified<<endl;
		for(i=0;i<n;i++){
			if(us[i].tag==1){
				cout<<us[i].name<<" "<<us[i].password<<endl;
			}
		}
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值