pat 甲级 1035 Password

简单题,第一次读错题,忘了要先输出有几个改的
↓忘了加计数的

#include <cstdio>
#include <iostream>
#include <cstring>

using namespace std;

int n, sum;
bool key = false;


int main(){

    scanf("%d",&n);
    for(int i=0; i<n; i++){
        string a;
        char arr[15];
        bool k = false;
        cin >> a >> arr;
        int l = strlen(arr);
        for(int j=0; j<l; j++){
            if(arr[j] == '1') { arr[j] = '@'; k = true;}
            if(arr[j] == '0') { arr[j] = '%'; k = true;}
            if(arr[j] == 'l') { arr[j] = 'L'; k = true;}
            if(arr[j] == 'O') { arr[j] = 'o'; k = true;}            
        }
        if(k == true) {
            cout << a << " ";
            for(int t=0; t<l; t++) cout << arr[t] ;
            cout << endl;
            key = true;

        }
    }

    if(key != true) printf("There are %d accounts and no account is modified\n",sum);

    return 0;
} 

发现之后不知道怎么存储
还是要巧妙运用string
同时注意特殊点:输出注意单复数 还有 is are

#include <cstdio>
#include <iostream>
#include <cstring>
#include <vector>

using namespace std;

int n, sum;
bool key = false;
vector<string> ans;


int main(){

    scanf("%d",&n);
    for(int i=0; i<n; i++){
        string a;
        string arr;
        bool k = false;
        cin >> a >> arr;
        int l = arr.length();
        for(int j=0; j<l; j++){
            if(arr[j] == '1') { arr[j] = '@'; k = true;}
            if(arr[j] == '0') { arr[j] = '%'; k = true;}
            if(arr[j] == 'l') { arr[j] = 'L'; k = true;}
            if(arr[j] == 'O') { arr[j] = 'o'; k = true;}            
        }
        if(k == true) {
            string b = a + " " + arr;
            ans.push_back(b);
            key = true;         
        }
        else sum++;
    }

    if(key != true) {
        if(sum == 1) printf("There is 1 account and no account is modified\n");
        else printf("There are %d accounts and no account is modified\n",sum);
    }
    else {
        int m = ans.size();
        cout << m << endl;
        for(int p=0; p<m; p++) cout << ans[p] << endl;
    }

    return 0;
} 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值