pat1035Password (20)

56 篇文章 0 订阅

题意分析:

(1)给出若干个PAT考试登陆账户,为了防止账户密码中有个别引起混淆的字母和数字(l,1,O,0),统计密码中出现可能混淆的字母的账户个数,并将修改后的账户按原来的顺序输出

可能坑点:

(1)注意:当没有出现混淆字母的账户时候,如果原来有N条记录,则要区分N=1和N!=1时候,输出结果的account和accounts单复数之别

(2)注意,在G++的编译器当中,当使用cout输出流的时候,cout<<"There are “<<N<<”...“<<endl;是错误的,一旦使用了这样的输出方式,会导致第二个测试案例过不去

#include <iostream>
#include <string.h>
#include <vector>
#include <stdio.h>
using namespace std;

struct userInfo
{
    string userName,passWord;
};
vector<userInfo>accounts;
bool check(string &passWord)
{
    bool isModified=0;
    for(int i=0;i<=passWord.length();i++)
    {
        if(passWord[i]=='1')
        {
            isModified=1;
            passWord[i]='@';
        }
        else if(passWord[i]=='0')
        {
            isModified=1;
            passWord[i]='%';
        }
        else if(passWord[i]=='l')
        {
            isModified=1;
            passWord[i]='L';
        }
        else if(passWord[i]=='O')
        {
            isModified=1;
            passWord[i]='o';
        }
    }
    return isModified;
}
int main()
{
    int N,i=0,cnt=0;
    scanf("%d",&N);
    string userName,passWord;
    userInfo temp;
    while(i<N)
    {
        cin>>userName>>passWord;
        if(check(passWord))
        {
            cnt++;
            temp.userName=userName;
            temp.passWord=passWord;
            accounts.push_back(temp);
        }
        i++;
    }
    if(cnt==0)
    {
        if(N==1) printf("There is 1 account and no account is modified\n");
        else printf("There are %d accounts and no account is modified\n",N);
    }
    else
    {
        cout<<cnt<<endl;
        vector<userInfo>::iterator it=accounts.begin();
        for(;it!=accounts.end();it++)cout<<(*it).userName<<" "<<(*it).passWord<<endl;
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值