听取UNK一片
查看原帖
听取UNK一片
1350295
jamie999楼主2025/6/27 19:46

帮忙看一下为什么第二个和第三个样例(题目给的)有一大堆UNK?

#include <bits/stdc++.h>
using namespace std;
map<string,string>m;
set<string>st;
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        string a,b;
        cin>>a>>b;
        m[a]=b;
        st.insert(a);
    }
    string s;
    cin>>s;
    string t="";
    s+=' ';
    // for(auto it=m.begin();it!=m.end();it++){
    //     cout<<it->first<<' '<<it->second<<endl;
    // }
    string ans="";
    // cout<<s<<endl;
    for(int i=0;i<s.size();i++){
        if(s[i]<='z'&&s[i]>='a'){
            t+=s[i];
        }
        else{
            if(1){
                // cout<<t<<' ';
                if(st.find(t)!=st.end()){
                    cout<<m[t];
                    ans+=m[t];
                }
                else{
                    cout<<"UNK";
                    ans+="UNK";
                }
                cout<<s[i];
                ans+=s[i];
                t="";
            }
        }
    }
    // cout<<endl;
    // for(int i=0;i<ans.size()-1;i++){
    //     cout<<s[i];
    // }
    return 0;
}
2025/6/27 19:46
加载中...