樣例對了 結果全 WA 感覺寫的沒錯啊 /yiw
查看原帖
樣例對了 結果全 WA 感覺寫的沒錯啊 /yiw
408019
ShanCreeperProEnder楼主2022/6/2 20:16
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fore(i,x,n) for(int i=x;i<=n;i++)
const int MAXX=10005;
const int mod=1;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-') f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
inline void write(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
inline void writesp(int x){
    write(x);
    putchar(' ');
}
inline void writeln(int x){
    write(x);
    putchar('\n');
}
inline string sread(){
    char ch=getchar(); string st1="";
    while(!((ch>='a')&&(ch<='z'))) ch=getchar();
    while((ch>='a')&&(ch<='z')) st1+=ch,ch=getchar();
    return st1;
}
map<string,queue<int>> ds;
int n,l,m;
string name,q;
signed main(){
#ifdef LOCAL
    freopen("debug_data.in","r",stdin);
    freopen("debug_data.out","w",stdout);
#endif
    n=read();
    fore(i,1,n){
        l=read();
        fore(j,1,l){
            name=sread();
            ds[name].push(i);
        }
    }
    m=read();
    fore(i,1,m){
        q=sread();
        while(!ds[q].empty()){
            writesp(ds[q].front());
            ds[q].pop();
        }
        puts("");
    }
}

大概思路就是每個字母都用一個隊列存,然後詢問單詞 q 時不斷彈隊首。

樣例過了的

2022/6/2 20:16
加载中...