10 分求助!
查看原帖
10 分求助!
554145
Night_sea_64楼主2022/10/18 21:53
#include<algorithm>
#include<iostream>
#include<cstring>
#include<map>
using namespace std;
map<string,bool>mp1,mp2;
//mp1[s] 表示 s 是不是在字典内
//mp2[s] 表示有没有前缀为 s 的字符串在字典内。
string num,ans[110];
char l[10][4]={
{' ',' ',' ',' '},
{' ','a','b','c'},
{' ','d','e','f'},
{' ','g','h','i'},
{' ','j','k','l'},
{' ','m','n',' '},
{' ','o','p','q'},
{' ','r','s','t'},
{' ','u','v','w'},
{' ','x','y','z'}};
void dfs(int step,string now,int cur)
{
    //cout<<step<<" "<<now<<" "<<cur<<" "<<num[step]<<endl;
    if(!mp2[now])return;
    if(step==int(num.size()))
    {
        ans[cur+1]=now;
        for(int i=1;i<=cur+1;i++)
        {
            cout<<ans[i];
            if(i<=cur)cout<<' ';
        }
        cout<<endl;
        exit(0);
    }
    int x=num[step]-'0';
    for(int i=1;i<=(x==5?2:3);i++)
    {
        dfs(step+1,now+l[x][i],cur);
        if(mp1[now])
        {
            ans[cur+1]=now;
            string ss=" ";
            ss[0]=l[x][i];
            dfs(step+1,ss,cur+1);
        }
    }
}
int main()
{
    int n;
    cin>>n>>num;
    for(int i=1;i<=n;i++)
    {
        string s;
        cin>>s;
        mp1[s]=1;
        for(int j=0;j<=s.size();j++)
            mp2[s.substr(0,j)]=1;
    }
    dfs(0,"",0);
    cout<<"No Solutions!"<<endl;
    return 0;
}

测了好几组数据都没有问题。好多点都显示 Wrong Answer.wrong output format Unexpected end of file - token expected

到底哪有问题啊,求求大佬们帮蒟蒻看看吧

2022/10/18 21:53
加载中...