字符串输出出现白色空格,感觉加了'\0'啊,求解答

图片说明

图片说明

题目如上,运行结果如上

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;
#define maxn 100
int Maxcount=0;//记录最大容纳几张牌
char Laststr[20]={0};
int hashtable[maxn];

void count13(int hashtable[],char str[],int Length,double b[])
{
    if(b[0]==13&&Length>Maxcount)
    {
        Maxcount=Length;
        strcpy(Laststr,str);
    }

    else
    {
        for(int i=0;i<maxn;i++)
        {
            if(hashtable[i]!=0)
            {
                //分+-*/四种情况
                double temp=b[0];
                //+
                if(Length!=0)
                {
                str[Length*2-1]='+';
                str[Length*2]=i;
                b[0]=temp+i;
                hashtable[i]--;
                count13(hashtable,str,Length+1,b);
                hashtable[i]++;
                }
                else
                {
                str[1]='+';
                str[1]=i;
                b[0]=temp+i;
                hashtable[i]--;
                count13(hashtable,str,Length+1,b);
                hashtable[i]++;
                }


                //-
                if(Length!=0)
                {
                str[Length*2-1]='-';
                str[Length*2]=i;
                b[0]=temp-i;
                hashtable[i]--;
                count13(hashtable,str,Length+1,b);
                hashtable[i]++;
                }
                else
                {
                str[1]='-';
                str[1]=i;
                b[0]=temp-i;
                hashtable[i]--;
                count13(hashtable,str,Length+1,b);
                hashtable[i]++;
                }

                //*
                if(Length!=0)
                {
                str[Length*2-1]='*';
                str[Length*2]=i;
                b[0]=temp*i;
                hashtable[i]--;
                count13(hashtable,str,Length+1,b);
                hashtable[i]++;
                }
                else
                {
                str[1]='*';
                str[1]=i;
                b[0]=temp*i;
                hashtable[i]--;
                count13(hashtable,str,Length+1,b);
                hashtable[i]++;
                }

                // /
                if(i!=0)
                {
                    if(Length!=0)
                    {
                    str[Length*2-1]='/';
                    str[Length*2]=i;
                    b[0]=temp/i;
                    hashtable[i]--;
                    count13(hashtable,str,Length+1,b);
                    hashtable[i]++;
                    }
                    else
                    {
                    str[1]='/';
                    str[1]=i;
                    b[0]=temp/i;
                    hashtable[i]--;
                    count13(hashtable,str,Length+1,b);
                    hashtable[i]++;
                    }
                }

            }
        }
    }
}

int main()
{
    int temp;//临时记录输入的数 ,要求的结果 
    double answer;
    fill(hashtable,hashtable+maxn,0);
    for(int i=0;i<6;i++)
    {
        scanf("%d",&temp);
        hashtable[temp]++;
     } 
    scanf("%d",&temp);//小明手上的牌
    scanf("%lf",&answer); 
    char str[20]={0};
    double b[maxn];
    b[0]=temp;
    str[0]=temp;
    count13(hashtable,str,0,b);
    for(int i=0;i<20;i++)
    {
        printf("%c",Laststr[i]);
    }
    cout<<Maxcount;
    return 0;
 } 

for(int i=0;i<20;i++)
{
    printf("%c",Laststr[i]);
}

你是按照字符输出的,和\0就没关系了。按照%s方式字符串输出,才会自动在\0截断