c++ 40 求解

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

Gordon5566 @ 2018-10-12 18:49:59

include<iostream>

include<cstdio>

include<algorithm>

include<cctype>

include<cmath>

include<cstring>

using namespace std; const int MAX=1000+10; int n,q,b,a[MAX],ans,c; bool flag; int main()
{ cin>>n>>q; for(int i=1;i<=n;i++) cin>>a[i]; sort(a+1,a+n+1); for(int i=1;i<=q;i++) { int x=-1; cin>>c>>b; for(int j=1;j<=n;j++) { x=-1; int p=a[j],q=b; while(q!=0) { if(p%10 != q%10 || p<q) break; p/=10; q/=10; x=a[j]; } if(x!=-1) { cout<<x<<"\n"; break; } }
if(x==-1) cout<<x<<"\n"; }
return 0; }


by Gordon5566 @ 2018-10-12 18:50:36

include<iostream>

include<cstdio>

include<algorithm>

include<cctype>

include<cmath>

include<cstring>

using namespace std; const int MAX=1000+10; int n,q,b,a[MAX],ans,c; bool flag; int main()
{ cin>>n>>q; for(int i=1;i<=n;i++) cin>>a[i]; sort(a+1,a+n+1); for(int i=1;i<=q;i++) { int x=-1; cin>>c>>b; for(int j=1;j<=n;j++) { x=-1; int p=a[j],q=b; while(q!=0) { if(p%10 != q%10 || p<q) break; p/=10; q/=10; x=a[j]; } if(x!=-1) { cout<<x<<"\n"; break; } }
if(x==-1) cout<<x<<"\n"; }
return 0; }


by RiverFun @ 2018-10-12 18:51:13

@Gordon5566

希望更丰富的展现?使用Markdown


by LinAPro @ 2018-10-12 18:52:03

```
dai ma
```

by Smile_Cindy @ 2018-10-12 18:55:28

@Gordon5566

MarkDown Thanks.


by Gordon5566 @ 2018-10-12 18:58:01

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstring>
using namespace std;
const int MAX=1000+10;
int n,q,b,a[MAX],ans,c;
bool flag;
int main()                                               
{
    cin>>n>>q;
    for(int i=1;i<=n;i++) cin>>a[i];
    sort(a+1,a+n+1);
    for(int i=1;i<=q;i++)
    {
        int x=-1;
        cin>>c>>b;
        for(int j=1;j<=n;j++)
        {
            x=-1;
            int p=a[j],q=b;
            while(q!=0)
            {
                if(p%10 != q%10 || p<q) break;
                p/=10;
                q/=10;
                x=a[j];
            }
            if(x!=-1)
            {
                cout<<x<<"\n";
                break;
            } 
        }        
        if(x==-1) cout<<x<<"\n";
    }   
    return 0;
}

|