请大佬查错

P3955 [NOIP2017 普及组] 图书管理员

三金Elsa @ 2017-11-12 17:34:01

#include<cstdio>
#include<algorithm>
using namespace std;
int a[1005],b;
int len[8]={1,10,100,1000,10000,100000,10000000,10000000};
int main()
{
    int n,q,i,j,lenz,ans=0;
    scanf("%d%d",&n,&q);
    for(i=1;i<=n;i++)
    scanf("%d",&a[i]);
    sort(a+1,a+1+n);
    for(i=1;i<=q;i++)
    {
        ans=0;
        scanf("%d%d",&lenz,&b);
        for(j=1;j<=n;j++)
        {
            if(a[i]==b){
                printf("%d\n",a[i]);
                ans=1;
                break;
            }
        }
            if(ans==1)continue;
            for(j=1;j<=n;j++)
            {
                if(a[i]%len[lenz]==b){
                printf("%d\n",a[i]);
                ans=1;
                break;
            }
            }
            if(ans==1)continue;
            printf("-1\n");
        }
    return 0;
}

为什么是错的?!


by 三金Elsa @ 2017-11-12 17:39:44

额,好吧我懂了//


by Gypsophila @ 2017-11-12 17:40:09

int len[8]={1,10,100,1000,10000,100000,10000000,10000000};

100000,10000000,10000000

0的个数不对


by 三金Elsa @ 2017-11-12 17:50:26

谢谢@ ACの666


by 三金Elsa @ 2017-11-12 17:51:32

那个#include<cstdio>

#include<algorithm>
using namespace std;
int a[1005],b;
int len[9]={1,10,100,1000,10000,100000,1000000,10000000,100000000};
int main()
{
    int n,q,i,j,lenz,ans=0;
    //freopen("librarian.in","r",stdin);
    //freopen("librarian.out","w",stdout);
    scanf("%d%d",&n,&q);
    for(i=1;i<=n;i++)
    scanf("%d",&a[i]);
    sort(a+1,a+1+n);
    for(i=1;i<=q;i++)
    {
        ans=0;
        scanf("%d%d",&lenz,&b);
        for(j=1;j<=n;j++)
        {
            if(a[j]==b){
                printf("%d\n",a[i]);
                ans=1;
                break;
            }
        }
        if(ans==1)continue;
        for(j=1;j<=n;j++)
        {
            if(a[j]%len[lenz]==b){
            printf("%d\n",a[j]);
            ans=1;
            break;
            }
        }
        if(ans==1)continue;
        printf("-1\n");
        }
    //fclose(stdin);
    //fclose(stdout);
    return 0;
}
@[ACの666](/space/show?uid=54745) 
还是不对?!70

by Gypsophila @ 2017-11-12 17:56:26

for(j=1;j<=n;j++)
        {
               if(a[j]==b){
                printf("%d\n",a[i]); //???? 应该输出a[j]啊
                ans=1;
                break;
            }
        }

by Gypsophila @ 2017-11-12 17:57:22

@诸葛子嵩


|