dev查看动态数组vector的时候,加入变量查看动态数组vector是不是只能查一次,查完就要删了,因为我不删除的话编译就运行不下去


#include <iostream>
#include <vector>
using namespace std;
int main() {
    int n;
    scanf("%d", &n);
    vector<string> v;
    for(int i = 0; i < n; i++) {
        string name, s;
        cin >> name >> s;
        int len = s.length(), flag = 0;
        for(int j = 0; j < len; j++) {
            switch(s[j]) {
                case '1' : s[j] = '@'; flag = 1; break;
                case '0' : s[j] = '%'; flag = 1; break;
                case 'l' : s[j] = 'L'; flag = 1; break;
                case 'O' : s[j] = 'o'; flag = 1; break;
            }
        }
        if(flag) {
            string temp = name + " " + s;
            v.push_back(temp);
        }
    }
    int cnt = v.size();
    if(cnt != 0) {
        printf("%d\n", cnt);
        for(int i = 0; i < cnt; i++)
            cout << v[i] << "\n";
    } else if(n == 1) {
        printf("There is 1 account and no account is modified");
    } else {
        printf("There are %d accounts and no account is modified", n);
    }
    return 0;
}

输入样例:
3
Team000002 Rlsp0dfa
Team000003 perfectpwd
Team000001 R1spOdfa

如图:

img


到v.push_back(temp);按f7也不动了

14-17行怎么case '0'和case '1'都是重复啊

你需要包含string头文件

#include <iostream>
#include <string>
#include <vector>
using namespace std;

修改后代码编译、运行都没啥问题:

img