1 solutions

  • 0
    @ 2025-3-9 21:17:33

    字典树做法,当然u_map也是可以的

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int N = 5e5+11;
    
    bool v[N];
    char str[55];
    int n, m, tot, cnt[N], tr[N][26];
    
    
    int main(){
    	cin>>n;
    	for(int i=0;i<n;i++){
    		scanf("%s",str);
    		int len = strlen(str), p = 0;
    		for(int j=0;j<len;j++){
    			int x = str[j] - 'a';
    			if(!tr[p][x]) tr[p][x] = ++ tot;
    			p = tr[p][x];
    		} cnt[p] ++; v[p] = 1;
    	}
    	
    	cin>>m;
    	for(int i=0;i<m;i++){
    		scanf("%s",str);
    		int len = strlen(str), p = 0;
    		for(int j=0;j<len;j++){
    			int x = str[j] - 'a';
    			if(!tr[p][x]) break;
    			p = tr[p][x]; 
    		} 
    		if(!v[p]) {printf("WRONG\n"); continue;}
    		if(!cnt[p]) {printf("REPEAT\n"); continue;}
    		cnt[p] --;printf("OK\n");
    	} return 0;
    }
    
    
    
    • 1

    Information

    ID
    521
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    9
    Tags
    # Submissions
    30
    Accepted
    3
    Uploaded By