1035 Password(简单题,字符串查找替换)

目录

题目​

测试样例

输入样例1

输出样例1

输入样例2

输出样例2

输入样例3

输出样例3

提交结果截图

带详细注释的源代码


题目

题目链接:

 1035 Password icon-default.png?t=L892https://pintia.cn/problem-sets/994805342720868352/problems/994805454989803520

测试样例

输入样例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

There is 1 account and no account is modified

输出样例3

There are 2 accounts and no account is modified

提交结果截图

带详细注释的源代码

#include <cstdio>
#include "string.h"
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct account_info
{
	string user_name;
	string password;
};
int n;

//1 (one) by @, 0 (zero) by %, l by L, and O by o
//检查是否含有四种字符至少其一,有则修改后返回true,无则直接返回false
bool check_and_change(account_info& ac)
{
	int flag = false;
	for(int i = 0; i < ac.password.length(); i++)//对密码中每个字符都检查一遍
		if (ac.password[i] == '1' || ac.password[i] == '0' || ac.password[i] == 'l' || ac.password[i] == 'O')//检查是否包含四种字符至少其一
		{
			flag = true;
			switch (ac.password[i])//修改字符
			{
			case '1':ac.password[i] = '@';
				break;
			case '0':ac.password[i] = '%';
				break;
			case 'l':ac.password[i] = 'L';
				break;
			case 'O':ac.password[i] = 'o';
				break;
			default:
				break;
			}
		}
	if (flag)
		return true;
	else
		return false;
}

int main()
{
	int num = 0; 
	vector<account_info>account;
	cin >> n;
	account_info tmp;
	for (int i = 0; i < n; i++)
	{
		cin >> tmp.user_name >> tmp.password;
        //只把需要修改的账号信息存储进向量中,因为不需要修改的账号信息是不需要输出的
		if (check_and_change(tmp))
		{
			account.push_back(tmp);
			num++;
		}
	}
	if (!num)//若是一个账号都不需要
	{
		if(n == 1)//注意语法区别
			cout << "There is 1 account and no account is modified" << endl;
		else
			cout << "There are " << n << " accounts and no account is modified" << endl;
	}
	else
	{
		cout << num << endl;
		for (int i = 0; i < account.size(); i++)
			cout << account[i].user_name << " " << account[i].password << endl;
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值