PAT甲级 1035 Password (20分)

1035 Password (20分)

题目链接:PAT A 1035
在这里插入图片描述
在这里插入图片描述

题目大意:输入第一行给出一个正整数n,随后n行每行给出用户名和密码(均为不含空格的字符串)。要求统计含有1,0,l,O的字符串的个数,并且将1替换成@,将0替换成%,将l替换成L,将O替换成o。如果没有能够替换的,则输出题目要求输出的句子(如果n等于1,句子中的are应该改为is)。

思路分析:非常简单的一道题,只需要建立一个结构体数组并且咋结构体中定义一个变量flag,如果需要替换,flag就为true,最后根据flag的结果进行输出即可。

#include<iostream>
#include<vector>
using namespace std;
struct id{
	string account, password; //用户名和密码 
	bool flag = false;
};
int main() {
	int n, cnt = 0; //cnt用来统计需要替换的字符串的个数 
	cin >> n;
	vector<id> v(n);
	for(int i = 0; i < n; i++) {
		cin >> v[i].account >> v[i].password;
		for(int j = 0; j < v[i].password.size(); j++) {
			if(v[i].password[j] == '1' || v[i].password[j] == '0' || v[i].password[j] == 'l' || v[i].password[j] == 'O') {
				v[i].flag = true;
				if(v[i].password[j] == '1')
					v[i].password[j] = '@';
				else if(v[i].password[j] == '0')
					v[i].password[j] = '%';
				else if(v[i].password[j] == 'l')
					v[i].password[j] = 'L';
				else
					v[i].password[j] = 'o';
			}
		}
		if(v[i].flag == true)
			cnt++;
	}
	if(cnt == 0) {
		if(n == 1) //there后面的are变为is 
			cout << "There is 1 account and no account is modified";
		else
			cout << "There are " << n << " accounts and no account is modified";
	}
	else {
		cout << cnt << endl;
		for(int i = 0; i < n; i++) {
			if(v[i].flag == true)
				cout << v[i].account << " " << v[i].password << endl;
		}
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值