流浪鬣狗 @ 2019-11-12 10:28:23
果然是我太蒻了
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
int n,q;
struct node
{
int num,l;
}xdd[1005];
bool cmp(node a,node b)
{
return a.num<b.num;
}
int To_know_how_long(int a)
{
int sum=0,t=a;
while(t>0)
{
sum++;
t/=10;
}
return sum;
}
bool Is_the_book_god_needs(int x,int a)
{
int i,l=To_know_how_long(a),t=xdd[x].num;
bool f=1;
t-=a;
if(t<0)return false;
if(t==0)return true;
for(i=1;i<=l;i++)if(t%10!=0)return false;
return true;
}
int i,j,god;
bool f;
int main()
{
scanf("%d%d",&n,&q);
for(i=1;i<=n;i++)
{
scanf("%d",&xdd[i].num);
xdd[i].l=To_know_how_long(xdd[i].num);
}
sort(xdd+1,xdd+n+1,cmp);
for(i=1;i<=q;i++)
{
f=1;
cin>>j>>god;
for(j=1;j<=n;j++)
{
if(Is_the_book_god_needs(j,god))
{
cout<<xdd[j].num<<endl;
f=0;
break;
}
}
if(f)cout<<"-1"<<endl;
}
return 0;
}
by Clark233 @ 2019-12-15 17:13:00
怎么办
by Clark233 @ 2019-12-15 17:13:51
by 红云爱吃糖 @ 2020-10-19 11:29:25
40分代码+1QAQ
#include<bits/stdc++.h>
using namespace std;
string a[2000],s;
bool cmp(string x,string y)
{
if(x.size()!=y.size())
return x.size()<y.size();
for(int i=0;i<x.size();i++)
if(x[i]>y[i])
return false;
return true;
}
int main()
{
int n,q,k;
cin>>n>>q;
for(int i=1;i<=n;i++)
cin>>a[i];
sort(a+1,a+n+1,cmp);
for(int i=1;i<=q;i++)
{
cin>>k>>s;
bool aflag=false;
for(int j=1;j<=n;j++)
{
bool flag=true;
int m=a[j].size();
for(int l=0;l<k;l++)
{
if(a[j][m+l-k]!=s[l])
{
flag=false;
break;
}
}
if(flag)
{
cout<<a[j]<<endl;
aflag=true;
break;
}
}
if(!aflag)
cout<<"-1"<<endl;
}
return 0;
}