问题标题: 酷町堂:求解

0
0
已解决
杨子逸
杨子逸
新手天翼
新手天翼

题目描述

计算机内信息编码采用二进制。现给定一串由小写字母构成的单词,请根据后面的编码原则,输出对应的二进制编码。已知编码长度n和编码的前n-5位,后5位的编码原则:a是00001,b是00010,c是00011,d是00100,以此类推,即后一个的编码是在前一个编码的基础上加1。

 

程序输入说明

输入共3行,第一行一个正整数n,表示编码长度;第二行给定前n-5位的二进制编码;第三行是m个小写字母构成的单词。

程序输出说明

m行,每行对应一个小写字母的二进制编码。

程序输入样例

8
110
will

程序输出样例

11010111
11001001
11001100
11001100

数据范围及提示

8<=n<=16,1<=m<=30

 

 

 

 

 

 

 

本人90分代码如下,找错:

#include<iostream>
#include<string>
using namespace std;
string a1[100]={"00001","00010","00011","00100","00101","00110","00111","01000","01001","01010","01011","01100","01101","01110","01111","10000"
,"10001","10010","10011","10100","10101","10110","10111","11000","11010","11011"};
char b1[100]={'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'};
string b;
int a,n;
int main()
{
cin>>n;
cin>>a>>b;
for(int i=0;i<b.size();i++)
{
for(int j=0;j<26;j++)
{
if(b[i]==b1[j])
{
cout<<a<<a1[j]<<endl;
break;
}
}
}
return 0;
}

求大佬解答


0
0
0
时梓繁
时梓繁
修练者
修练者

AI课堂吗?

时梓繁在2018-08-28 09:22:42追加了内容

是的话:

#include<bits/stdc++.h>

using namespace std;

int d[201][201],dis[201],f[201];

int main()

{

    int n,a,b;

    cin>>n>>a>>b;

    for (int i=1;i<=n;++i)

    {

        for (int j=1;j<=n;++j)

          d[i][j]=1000000;

        d[i][i]=0;

}

    int k;

    for (int i=1;i<=n;++i)

    {

        scanf("%d",&k);

        if (i+k<=n) d[i][i+k]=1;

        if (i-k>=1) d[i][i-k]=1;

}

    for (int i=1;i<=n;++i)

dis[i]=d[a][i];

    int minn,t;

    for (int i=1;i<=n;++i)

    {

        minn=1000000;

        for (int j=1;j<=n;++j)

          if (f[j]==0&&dis[j]<minn)

          {

              minn=dis[j];

              t=j;

          }

        f[t]=1;

        for (int j=1;j<=n;++j)

          dis[j]=min(dis[j],dis[t]+d[t][j]);

}

    if (dis[b]!=1000000)

      cout<<dis[b];

    else

      cout<<-1;

    return 0;

}

时梓繁在2018-08-28 09:24:26追加了内容

不是的话:请问题号是什么

0
0
叶子煊
叶子煊
中级光能
中级光能

我将你不对的地方修改了一下

(也就是你代码有误的地方)

但改完后依然是90分

此为代码:

#include<iostream>
#include<string>
using namespace std;
string a1[100]={"00001","00010","00011","00100","00101","00110","00111","01000","01001","01010","01011","01100","01101","01110","01111","10000","10001","10010","10011","10100","10101","10110","10111","11000","11001","11010"};
char b1[100]={'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'};
string b;
int a,n;
int main()
{
    cin>>n;
    if(n>5)
    cin>>a;
    cin>>b;
    for(int i=0;i<b.size();i++)
    {
        for(int j=0;j<26;j++)
        {
            if(b[i]==b1[j])
            {
                cout<<a<<a1[j]<<endl;
                break;
            }
        }
    }   
    return 0;
}
   

请自己再想想!!!

望采纳!!!

~~~~~~~~~~~~~~~~~~~~~~

我要回答