栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

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

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

目录

题目​

测试样例

输入样例1

输出样例1

输入样例2

输出样例2

输入样例3

输出样例3

提交结果截图

带详细注释的源代码


题目

题目链接:

 1035 Password https://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 
#include "string.h"
#include 
#include 
#include 
#include 
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; 
	vectoraccount;
	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;
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/298165.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号