首页 > 试题广场 >

Password (20)

[编程题]Password (20)
  • 热度指数:3527 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解
To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem is that there are always some confusing passwords since it is hard to distinguish 1 (one) from l (L in lowercase), or 0 (zero) from O (o in uppercase). One solution is to replace 1 (one) by @, 0 (zero) by %, l by L, and O by o. Now it is your job to write a program to check the accounts generated by the judge, and to help the juge modify the confusing passwords.

输入描述:
Each input file contains one test case.  Each case contains a positive integer N (<= 1000), followed by N lines of accounts.  Each account consists of a user name and a password, both are strings of no more than 10 characters with no space.


输出描述:
For each test case, first print the number M of accounts that have been modified, then print in the following M lines the modified accounts info, that is, the user names and the corresponding modified passwords.  The accounts must be printed in the same order as they are read in.  If no account is modified, print in one line "There are N accounts and no account is modified" where N is the total number of accounts.  However, if N is one, you must print "There is 1 account and no account is modified" instead.
示例1

输入

3<br/>Team000002 Rlsp0dfa<br/>Team000003 perfectpwd<br/>Team000001 R1spOdfa

输出

2<br/>Team000002 RLsp%dfa<br/>Team000001 R@spodfa
//1010.Password
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
    int n,m=0,f1=0,f2=0; cin>>n;
    vector<string> t; //vector用push_back函数 不用越界[i]赋值
    string t1,t2;
    for(int i=0;i<n;i++){
        cin>>t1>>t2;
        f2=0;
        for(int i=0;i<t2.size();i++){
            //cout<<t2[i];
            switch(t2[i]){
                case '0': t2[i]='%'; f2=1; break;
                case '1': t2[i]='@'; f2=1; break;
                case 'l': t2[i]='L'; f2=1; break;
                case 'O': t2[i]='o'; f2=1; break;
            }
        }
        if(f2==1){t.push_back(t1+" "+t2); f1=1; m++;}

    }
    if(f1==0){
        cout<<"There";
        n==1?cout<<" is ":cout<<" are ";
        cout<<n<<" account"; n==1?cout<<"":cout<<"s";
        cout<<" and no account is modified"<<endl;
    }else{
        cout<<m<<endl;
        for(int i=0;i<m;i++) cout<<t[i]<<endl;
    }
    return 0;
}
发表于 2019-03-01 09:40:40 回复(0)
//java也许不是最简单最快最优的或者最精巧,但是各种api面对简单题非常好用且不出错
//思路非常清晰, 总之看起来很舒服的那种(笑
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		ArrayList<String> lista=new ArrayList<String>();
		ArrayList<String> listb=new ArrayList<String>();
		for(int i=0;i<n;i++){
			String a=in.next();
			String b=in.next();
			if(b.contains("1")||b.contains("0")||b.contains("l")||b.contains("O")){
				b=b.replaceAll("1","@");
				b=b.replaceAll("0","%");
				b=b.replaceAll("l","L");
				b=b.replaceAll("O","o");
				lista.add(a);
				listb.add(b);
			}
		}
		if(lista.isEmpty()){
			if(n==1){
			System.out.println("There is "+n+ " account and no account is modified");}
			else System.out.println("There are "+n+ " accounts and no account is modified");
		}else{
			System.out.println(lista.size());
			for(int i=0;i<lista.size();i++){
				System.out.println(lista.get(i)+" "+listb.get(i));
			}
		}
	}
}


编辑于 2016-10-24 13:07:54 回复(0)
一开始想用string类做,c++的这个类比java难用多了,没办法,换成字符串数组做了

#include<stdio.h>

#include<iostream>

#include<string>

#include<string.h>

#include<vector>

using namespace std;

struct Node2

{

    char name[11];

    char psd1[11];

    bool isModified;

};


bool handleString(char b2[11])

{

    bool result = false;

    int lengh = strlen(b2);

    for(int i=0;i<lengh;i++)

    {

        if(b2[i]=='1')

        {

            b2[i]='@';

            result = true;

        }else if(b2[i]=='0')

        {

            b2[i]='%';

            result = true;

        }

        else if(b2[i]=='O')

        {

            b2[i]='o';

            result = true;

        }else if(b2[i]=='l')

        {

            b2[i]='L';

            result = true;

        }

    }

    return result;

}

int main()

{

    int N;

    scanf("%d",&N);

    vector<Node2*> input;

    int sum = 0;

    for(int i=0;i<N;i++)

    {

        char a1[11],b2[11];

        scanf("%s %s",a1,b2);

        bool isMod = handleString(b2);

        Node2 *tmp = new Node2;

        

        strcpy(tmp->name , a1);

        

        if(isMod)

        {

            sum++;

            strcpy(tmp->psd1,b2);

            //tmp->psd1 = b2;

            tmp->isModified = true;

        }else

        {

            tmp->isModified = false;

            strcpy(tmp->psd1,b2);

        }

        input.push_back(tmp);

    }

    if(sum==0&&N==1)

        cout<<"There is "<<N<<" account and no account is modified"<<endl;

    else if(sum==0&&N!=1)

        cout<<"There are "<<N<<" accounts and no account is modified"<<endl;

    else 

    {

        cout<<sum<<endl;

        for(int i=0;i<input.size();i++)

        {

            if(input[i]->isModified)

            {

                cout<<input[i]->name<<" "<<input[i]->psd1<<endl;

            }

        }

    }

    return 0;

}


发表于 2018-03-06 21:58:59 回复(0)
#include <iostream>
#include <cstring>
using namespace std;

struct guy{
    char name[15];
    char password[15];
}guy[1010];

int main(){
    int n,num=0;char a[15],b[15];
    cin>>n;
    for(int j=0;j<n;j++){
        cin>>a>>b;
        int len=strlen(b);int p=0;
        for(int i=0;i<len;i++){
            if(b[i]=='1'){
                b[i]='@';
                p=1;
            }
            else if(b[i]=='0'){
                b[i]='%';
                p=1;
            }
            else if(b[i]=='l'){
                b[i]='L';
                p=1;
            }
            else if(b[i]=='O'){
                b[i]='o';
                p=1;
            }
            else continue;
        }
        
        if(p==1){
            strcpy(guy[num].name,a);
            strcpy(guy[num++].password,b);
        }
    }
    if(n==1&&num==0) cout<<"There is 1 account and no account is modified";
    else if(n>1&&num==0) cout<<"There are "<<n<<" accounts and no account is modified";
    else{
        cout<<num<<'\n';
        for(int i=0;i<num;i++)
            cout<<guy[i].name<<" "<<guy[i].password<<'\n';
    }

    return 0;
}

发表于 2018-01-17 20:42:51 回复(0)
import re

a = {'0':'%','1':'@','O':'o','l':'L'}
b = re.compile('1|0|O|l')
c = input()
d = []
e = 0

for i in xrange(c):
    f = raw_input().split()
    g = b.sub(lambda x: a[re.escape(x.group(0))], f[1])
    if g != f[1]:
        d.append((f[0], g))
        e += 1
        
if e == 0:
    if c == 1:
        print "There is 1 account and no account is modified"
    else:
        print "There are {N} accounts and no account is modified".format(N = c)
else:
    print e
    for m, n in d:
        print m, n

编辑于 2017-01-23 12:16:29 回复(0)
啥头像
贴个python的
modifiedCharDict = {'1':'@', '0':'%', 'l':'L', 'O':'o'}
modifiedChars = ('1', '0', 'l', 'O')
def isConfusing(string):
    flag = False
    for i in string:
        if i in modifiedChars:
            flag = True
    return flag
def getCorrectPwd(string):
    rlt = ''
    for i in string:
        if i in modifiedChars:
            rlt += modifiedCharDict[i]
        else:
            rlt += i
    return rlt
    
N = input()
M = 0
rlt = []
for i in range(N):
    string = raw_input().strip().split()
    if isConfusing(string[1]):
        M += 1
        string[1] = getCorrectPwd(string[1])
        rlt.append(string)
if M == 0:
    if N == 1:
        print("There is 1 account and no account is modified")
    else:
        print("There are %d accounts and no account is modified" % N)
else:
    print(M)
    for i in rlt:
        print(' '.join(i)) 


发表于 2016-01-23 23:08:02 回复(0)
#include<bits/stdc++.h>
using namespace std;

const int Max=1010;

struct T {
	string name;
	string password;
	int flag=0;
} t[Max];

int main() {
	int n,sum=0;
	cin>>n;
	for(int i=0; i<n; i++) {
		cin>>t[i].name>>t[i].password;
		t[i].flag=0;
	}
	for(int i=0; i<n; i++) {
		int m=t[i].password.size();
		for(int j=0; j<m; j++) {
			if(t[i].password[j]=='l') {
				t[i].password[j]='L';
				t[i].flag=1;
			} else if(t[i].password[j]=='0') {
				t[i].password[j]='%';
				t[i].flag=1;
			} else if(t[i].password[j]=='O') {
				t[i].password[j]='o';
				t[i].flag=1;
			} else if(t[i].password[j]=='1') {
				t[i].password[j]='@';
				t[i].flag=1;
			}
		}
		if(t[i].flag) sum++;
	}
	if(sum==0) {
		if(n>1) printf("There are %d accounts and no account is modified",n);
		if(n==1) printf("There is 1 account and no account is modified");
	} else {
		cout<<sum<<endl;
		for(int i=0; i<n; i++) {
			if(t[i].flag) {
				cout<<t[i].name<<" "<<t[i].password<<endl;
			}
		}
	}
	return 0;
}

发表于 2022-11-07 15:29:30 回复(1)
我的代码有待优化,但是有几个自己发现的技巧。
1、结果用stuct最大数组保存,设flag字段方便输出。
2、设128大小的char数组,用于替换字符,这个大小可以存下所有的ASCII符。意味着可以像map那样使用这个数组,如replace['0'] replace['1']这样用
3、定制的输出多设几个flag没坏处。
这是我第一个碰到存储结果最后一起输出的题目,其他的都可以处理时就输出

#include<iostream>
using namespace std;
struct player {
	string user;
	string pwd;
	bool changed=false;
} P[1001];
int main() {
	bool perfect=true;
	int N,n;
	cin>>N;
	n=N;
	string user,pwd;
	char replace[128]= {0};
	replace['1']='@';
	replace['0']='%';
	replace['l']='L';
	replace['O']='o';
	int j=0,num=0;
	while(N--) {
		cin>>user>>pwd;
		string newpwd;
		bool changed=false;
		for(int i=0; i<pwd.size(); i++) {
			if(pwd[i]=='1'||pwd[i]=='0'||pwd[i]=='O'||pwd[i]=='l') {
				newpwd+=replace[pwd[i]];
				perfect=false;
				changed=true;
			} else {
				newpwd+=pwd[i];
			}
		}
		
		if(changed) {
			num++;
			perfect=false;
			P[j].changed=true;
			P[j].user=user;
			P[j].pwd=newpwd;
		}
		j++;
	}
	if(perfect&&n==1) {
		cout<<"There is 1 account and no account is modified";
	} else if(perfect) {
		cout<<"There are "<<n<<" accounts and no account is modified";
	} else {
		cout<<num<<endl;
		for(int i=0; i<=1000; i++) {
			if(P[i].changed) {
				cout<<P[i].user<<" "<<P[i].pwd<<endl;
			}
		}
	}
	return 0;
}


发表于 2020-02-03 13:11:13 回复(0)
//
// Created by 924905699 on 2019/9/5.
//
//定义一个结构体保存name,password,falg,falg表示该结构体是否被修改
#include <bits/stdc++.h>
using namespace std;
struct node{
    string name;
    string password;
    bool falg;
};
void judge(node& t, int& cnt) {
    int len = t.password.size();
    for(int i = 0; i < len; i++) {
        if(t.password[i] == '1') {
            t.password[i] = '@';
            t.falg = true;
        } else if(t.password[i] == '0') {
            t.password[i] = '%';
            t.falg = true;
        } else if(t.password[i] == 'l') {
            t.password[i] = 'L';
            t.falg = true;
        } else if(t.password[i] == 'O') {
            t.password[i] = 'o';
            t.falg = true;
        }
    }
    if(t.falg) {
        cnt++;
    }
}

node s[1010];
int main(){
    int num;
    cin>>num;
    int cnt=0;//记录修改的次数
    for (int i = 0; i <num ; ++i) {
        cin>>s[i].name>>s[i].password;
        s[i].falg=false;//falg默认为flase
    }
    for (int i = 0; i <num ; ++i) {
        judge(s[i],cnt);
    }
    if(cnt==0) {
        if(num==1)
        cout << "There is 1 account and no account is modified";
        else
            cout<<"There are "<<num<<" accounts and no account is modified";
    } else{
        cout<<cnt<<endl;
        for (int i = 0; i <num ; ++i) {
            if(s[i].falg==true)
                cout<<s[i].name<<" "<<s[i].password<<endl;
        }
    }
    return 0;
}

发表于 2019-09-05 21:59:49 回复(0)
一道简单的字符串题
#include "iostream"
#include "cstring"
using namespace std;

int main(){     int N,i,j,count = 0,flag = 0;     string a[1005],b[1005],c[1005],d[1005];     cin>>N;     for(i = 0;i < N; i++)         cin>>b[i]>>a[i];         for(i = 0;i < N; i++){             flag = 0;         for(j = 0;j < a[i].length(); j++){             if(a[i][j] == '1'){                 a[i][j] = '@';                 flag = 1;             }             if(a[i][j] == '0'){                 a[i][j] = '%';                 flag = 1;             }             if(a[i][j] == 'l'){                 a[i][j] = 'L';                 flag = 1;             }             if(a[i][j] == 'O'){                 a[i][j] = 'o';                 flag = 1;             }         }             if(flag){                 c[count] = a[i];                 d[count] = b[i];                 count++;             }         }         if(count == 0){             if(N == 1)                 cout<<"There is 1 account and no account is modified";             else
                cout<<"There are " << N << " accounts and no account is modified";
            return 0;
        }         cout<<count<<endl;         for(i = 0;i < count; i++)         cout<<d[i]<<" "<<c[i]<<endl;     return 0;
}

发表于 2018-08-29 10:59:16 回复(0)
思路:就是逐个比较
#include <iostream>
#include <fstream>
#include <string> 
#include <vector>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

struct stu
{
    string ID;
    string pwd;
    //stu(string _ID, string _pwd):ID(_ID),pwd(_pwd){}
};

bool Mod(string & str, int &count)
{
    int tempCount = count;
    bool changed = false;
    for(int i=0; str[i]!='\0'; i++)
    {
        switch(str[i])
        {
            case '1':
                str[i] = '@';
                count ++;
                break;
            case '0':
                str[i] = '%';
                count ++;
                break;
            case 'l':
                str[i] = 'L';
                count ++;
                break;
            case 'O':
                str[i] = 'o';
                count ++;
                break;
            default:
                break;
        }
    }
    if(tempCount != count)
    {
        changed = true;
    }
    return changed; 
}

int main(int argc, char** argv) {
    //ifstream cin("test.txt");
    int n;
    while(cin >> n)
    {
        string pwd,ID;
        vector<struct stu> v(n);
        vector<int> b; 
        int numMod = 0;
        for(int i=0; i<n; i++)
        {
            cin >> ID >> pwd;
            v[i].ID = ID;
            v[i].pwd = pwd;
            if(Mod(v[i].pwd, numMod))
            {
                b.push_back(i);
            }
        }
        if(numMod != 0)
        {
            cout << b.size() << endl;
            for(int i=0; i<b.size(); i++)
            {
                cout << v[b[i]].ID << " " << v[b[i]].pwd << endl;
            }
        }
        else
        {
            if(v.size() == 1)
            {
                cout << "There is 1 account and no account is modified" << endl;
            }
            else
            {
                cout << "There are " << v.size() << " accounts and no account is modified" << endl;
            }
        }
        
    }
    system("pause"); 
    return 0;
}

发表于 2018-08-18 19:15:53 回复(0)
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(){
    int n;
    cin>>n;
    string d1,d2;
    int flag=0,flag1=0;
    vector<string> a(n),c(n);
    for(int i=0;i<n;i++){
       cin>>d1>>d2;
       int m=0;
       for(int i=0;i<d2.length();i++){
           if(d2[i]=='1'){
             d2[i]='@';
             m=1;
             flag1=1;
         }
           else if(d2[i]=='0'){
             d2[i]='%';
             m=1;
             flag1=1;
         }
           else if(d2[i]=='l'){
             d2[i]='L';
             m=1;
             flag1=1;
        }
           else if(d2[i]=='O'){
             d2[i]='o';
             m=1;
             flag1=1;
       }}
       if(m==1){
          a[flag]=d1;
          c[flag]=d2;
          flag++;
         }
      }
      if(flag1==0){
          if(n==1)
            cout<<"There are 1 account and no account is modified"<<endl;
          else
           cout<<"There are "<<n<<" accounts and no account is modified"<<endl;
      }else{
          cout<<flag<<endl;
          for(int i=0;i<flag;i++){
              cout<<a[i]<<" "<<c[i]<<endl;
        }
      }
 

发表于 2018-05-13 00:29:24 回复(0)
#include<iostream>
#include<vector>
#include<string>
using namespace std;

struct Account{
    string usrname;
    string passwd;
    string passwd_modified;
};

int main(){
    int n;
    cin>>n;
    vector<Account> a(n);
    vector<int> idx;
    for(int i=0; i<n; ++i){
        cin>>a[i].usrname>>a[i].passwd;
    }
    for(int i=0; i<n; ++i){
        string s = a[i].passwd;
        a[i].passwd_modified = a[i].passwd;
        int modified = 0;
        for(int j=0; j<s.size(); ++j){
            if(s[j]=='1')    a[i].passwd_modified[j] = '@';
            else if(s[j]=='0')    a[i].passwd_modified[j] = '%';
            else if(s[j]=='l')    a[i].passwd_modified[j] = 'L';
            else if(s[j]=='O')    a[i].passwd_modified[j] = 'o';
            if(s[j]=='1'||s[j]=='0'||s[j]=='l'||s[j]=='O') modified = 1;
        }
        if(modified==1)    idx.push_back(i);
    }
    int m = idx.size();
    if(m==0){
        if(n==1)    cout<<"There is 1 account and no account is modified";
        else    cout<<"There are "<<n<<" accounts and no account is modified";
        return 0;
    }
    cout<<m<<endl;
    for(int i=0; i<m; ++i){
        cout<<a[idx[i]].usrname<<" "<<a[idx[i]].passwd_modified<<endl;
    }
    return 0;
}

发表于 2018-02-13 20:44:03 回复(0)
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
using namespace std;


bool check_and_tr(string & s)
{
    int len = 0;
    len = s.length();

    bool flag = false;
    for (int i = 0;i < len;++i)
    {
        switch (s[i])
        {
        case '1':
            s[i] = '@';
            flag = true;
            break;
        case '0':
            s[i] = '%';
            flag = true;
            break;
        case 'l':
            s[i] = 'L';
            flag = true;
            break;
        case 'O':
            s[i] = 'o';
            flag = true;
            break;
        default:
            break;
        }
    }
    return flag;
}


int main()
{
    ifstream cin("case.txt");

    int N;
    cin >> N;
    string username = "";
    string password = "";

    vector <string> result;
    int num = 0; // 计数,修改过的数量
    for (int i = 0;i < N;i++)
    {
        cin >> username >> password;
        if (check_and_tr(password)) // modify
        {
            num++;
            result.push_back(username + " " + password);
        }
    }

    if (num == 0)
    {
        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 < num;++i)
        {
            cout << result[i] << endl;
        }
    }
    getchar();
    return 0;
}

发表于 2017-11-23 21:52:19 回复(0)
#include <map>
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
using namespace std;
const int MAX = 100 + 5;

map<char, char> m = { {'1', '@'},
                      {'0', '%'},
                      {'l', 'L'},
                      {'O', 'o'}  };

struct Count{
    string id;
    string password;
    bool flag = false;

    Count(){};

    void read(){
        cin >> id >> password;
    }

    void modify(){
        for(unsigned int i=0;i<password.size();i++){
            char c = password[i];
            if(c == '1' || c == '0' || c == 'l' || c == 'O'){
                if(!flag) flag = true;
                password[i] = m[c];
            }
        } 
    }

};

int main(){
    int N;
    vector<Count> v;
    v.clear();
    cin >> N;
    int N_temp = N;
    while(N_temp --){
        Count s;
        s.read();
        s.modify();
        if(s.flag) v.push_back(s);
    }
    int cnt = v.size();
    if(cnt == 0) printf("There %s %d %s and no account is modified\n", (N>1 ? "are" : "is"), N, (N>1 ? "accounts" : "account"));
    else{
        cout << cnt << endl;
        for(int i=0;i<cnt;i++)
            cout << v[i].id << " " << v[i].password << endl;
    }
    return 0;
}

发表于 2017-07-29 00:24:43 回复(0)
题目不难,但容易在格式上翻车
n==1时 用 is 1 account
n>1时   用 are n accounts
#include <iostream>
#include <vector>
#include <string>
#include<algorithm>
using namespace std;
typedef struct
{
	string name;
	string password;
	bool symbol = false;
	void test()
	{
		for (auto &c : password)
		{
			if (c == '1')
			{
				symbol = true;
				c = '@';
			}
			else if (c == '0')
			{
				symbol = true;
				c = '%';
			}
			else if (c == 'l')
			{
				symbol = true;
				c = 'L';
			}
			else if (c == 'O')
			{
				symbol = true;
				c = 'o';
			}
			else
				continue;
		}
	}
}node;

int main()
{
	int length;
	while (cin >> length)
	{
		vector<node> data;
		for (int i = 0; i < length; i++)
		{
			node tmp;
			cin >> tmp.name >> tmp.password;
			tmp.test();
			if (true == tmp.symbol)
				data.push_back(tmp);
		}
		if (data.size() == 0)
		{
			if (length == 1)
				cout << "There is " << length << " account and no account is modified" << endl;
			else
				cout << "There are " << length << " accounts and no account is modified" << endl;
			continue;
		}
		else
		{
			cout << data.size() << endl;
			for (vector<node>::iterator it = data.begin(); it != data.end(); it++)
				cout << it->name << " " << it->password << endl;
		}
	}
	return 0;
}

发表于 2017-04-28 14:00:17 回复(0)
#include <stdio.h>
#include <string.h>

typedef struct data_s
{
	char name[15];
	char passwd[15];
}data_t;

data_t data[1010];

data_t buf[1010];


//1:subtitute  0:no change
int subtitute(int n)
{
	int flag = 0;
	int i;
	for(i=0;i<15;i++)
	{
		if(data[n].passwd[i] == '1')
		{
			data[n].passwd[i] = '@';
			flag = 1;
		}
	    if(data[n].passwd[i] == '0')
		{
			data[n].passwd[i] = '%';
			flag = 1;						
		}
		if(data[n].passwd[i] == 'l')
		{
			data[n].passwd[i] = 'L';
			flag = 1;			
		}
		if(data[n].passwd[i] == 'O')
		{
			data[n].passwd[i] = 'o';
			flag = 1;						
		}
	}
	
	return flag;
}


int main()
{
    int n,i;
    int res;
    int j = 0;
    scanf("%d",&n);
    getchar();
    
    for(i=0;i<n;i++)
    {
    	scanf("%s",data[i].name);
    	scanf("%s",data[i].passwd);
    }
    
    
    
    for(i=0;i<n;i++)
    {
        res = subtitute(i);
        
        if(res == 1)
        {
        	memcpy(buf[j].name,data[i].name,15);
        	memcpy(buf[j].passwd,data[i].passwd,15);
        	j++;
        }
        
    }
    
    if(j == 0)
    {
    	printf("There %s %d %s and no account is modified\n",(n>1)?"are":"is",n,(n>1)?"accounts":"account");
    	
    	return 0;
    }
    else
    {
    	printf("%d\n",j);
    }
    
    for(i=0;i<j;i++)
    {
    	printf("%s ",buf[i].name);
    	printf("%s\n",buf[i].passwd);    	
    }

    return 0;
} 
编辑于 2017-03-13 09:37:19 回复(0)
#include <iostream>
#include <vector>
#include <string>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;

int N;
bool flag;
struct namePass{
	string name;
	string password;
};

vector<namePass> a, b;
bool change(string &s){
	flag = false;
	for(int i = 0;i < s.length();i++){
		switch(s[i]){
			case '0': s[i] = '%';flag = true;break;
			case '1': s[i] = '@';flag = true;break;
			case 'l': s[i] = 'L';flag = true;break;
			case 'O': s[i] = 'o';flag = true;break;
			default: break;
		}
	}
	return flag;
}
int main(int argc, char** argv) {
	cin >> N;
    a.resize(N);
	for(int i = 0;i < N;i++){
		cin >> a[i].name >> a[i].password;
	}
	for(int i = 0;i < N;i++){
		if(change(a[i].password) == true){
			b.push_back(a[i]);
		}
	}
	int j = b.end() - b.begin();
	if(j == 0 && N == 1){
		cout << "There is 1 account and no account is modified" << endl;
		return 0;
	}

	if(j == 0){
		cout << "There are " << N << " accounts and no account is modified" << endl;
		return 0;
}
	cout << j << endl;
	for(int i = 0;i < j;i++){
		cout << b[i].name << " " << b[i].password << endl;
	}
	return 0;
}

发表于 2016-01-29 22:35:17 回复(0)
同第一个同学的观点。。。在is和are的问题上修改了两次,蛋疼。。
发表于 2016-01-08 14:05:01 回复(0)
n==1时 用 is 1 account
n>1时   用 are n accounts
竟然一个一个单词看下去还看不粗来。。改了俩次。。。T。T
发表于 2015-07-19 22:45:11 回复(1)

问题信息

难度:
20条回答 6846浏览

热门推荐

通过挑战的用户