美文网首页
A1035 Password (20分)

A1035 Password (20分)

作者: km15 | 来源:发表于2020-01-18 12:18 被阅读0次

    learn && wrong;
    1、逻辑又错了,这里有加数字的,一开头有加一个数字,处理就不同了,用一个数组来存并且统计
    2、每次进入前flag要更新为ture
    3、下标i错了,因为i,中间有一个没问题,然后他就过了!以i为第一个下标不对的!也就是i为2是空的,所以什么也没输出,但是输出了换行

    4、他用结构体做,而我用了string数组做,每输入一个,结构体就初始化一次,其实没什么区别,也没什么特别的

    题目要求:
    1、1->@
    2、0->%
    3、小写l变大写
    4、大写O变小写

    输出格式
    1、没有修改的时候,包含1或者n个
    2、有修改的时候,输出个数,并且把修改过的输出

    编程思想:
    1、读入总的个数,读入字符串,逐个扫描,用if_else if修改,
    2、用一个标记为记录有没有修改,之前的一招,身份证验证flag,然后再判断总是是否N,分情况你输出

    -----新的编程思想:
    1、读入个数,修改,并且判定是true或者flag,是就压入数组,最后先输出个数,再输出数组元素
    2、如果数组个数为0,则根据n判定输出哪一句!

    */

    #include <iostream>
    #include <string>
    using namespace std;
    
    string array1[1001][3];
    
    int main()
    {
        int n; //输入的个数
        cin >> n;
        string name;
        string s1;
        bool flag;//标记位,标记有没发生修改
        int count = 0;
        
         //——————
    
        for (int i = 0;i < n;i++) {  //检查是否修改,如果需要,则修改,并修改标记位,如果修改完,最后压入数组并且数量+1
            cin >> name>> s1;
            flag = true;//每次进入前flag要更新为ture
            for (int j = 0;j < s1.size();j++) {
                if (s1[j] == '1')
                {
                    s1[j] = '@';
                    flag = false;
                }
                else if (s1[j] == '0') {
                    s1[j] = '%';
                    flag = false;
                }
                else if (s1[j] == 'l') {
                    s1[j] = 'L';
                    flag = false;
                }
                else if (s1[j] == 'O') {
                    s1[j] = 'o';
                    flag = false;
                }
            }
            if (flag == false){
                array1[count][0] = name;
                array1[count][1] = s1;
                ++count;
            }
        }
    
        if (count > 0) {
            cout << count << endl;
            for (int i = 0;i < count;i++) {
                cout << array1[i][0] <<" "<< array1[i][1] << endl;  //我懂为什么了,中间有一个没问题,然后他就过了!以i为第一个下标不对的!也就是i为2是空的,所以什么也没输出,但是输出了换行
            }
        }
        else if ((count == 0) && (n >= 2)) { //判断是否修改过,或者修改过的同时,n是否为1
            cout << "There are " << n << " accounts and no account is modified" << endl;
        }
        else if ((count == 0) && (n == 1)) {
            cout << "There is 1 account and no account is modified" << endl;
        }
    
        return 0;
        
    }
    
    

    相关文章

      网友评论

          本文标题:A1035 Password (20分)

          本文链接:https://www.haomeiwen.com/subject/luzczctx.html