001__c @ 2019-05-31 21:05:46
using namespace std;
int main()
{
int n,q,a[1001],b[1001],k[1001],i,j,l,w[1001],flag;
cin>>n>>q;
for(i=1;i<=n;i++)
cin>>a[i];
sort(a,a+n+1);
for(i=1;i<=q;i++)
cin>>k[i]>>b[i];
for(i=1;i<=q;i++)
w[i]=1;
for(i=1;i<=q;i++)
for(j=1;j<=k[i];j++)
w[i]=w[i]*10;
for(i=1;i<=q;i++)
{
for(l=1;l<=n;l++)
{
if(a[l]%w[i]==b[i])
{
cout<<a[l]<<endl;
break;
}
else if(l==n)
cout<<"-1"<<endl;
}
}
return 0; }
by 001__c @ 2019-05-31 21:08:57
int n,q,a[1001],b[1001],k[1001],i,j,l,w[1001],flag;
cin>>n>>q;
for(i=1;i<=n;i++)
cin>>a[i];
sort(a,a+n+1);
for(i=1;i<=q;i++)
cin>>k[i]>>b[i];
for(i=1;i<=q;i++)
w[i]=1;
for(i=1;i<=q;i++)
for(j=1;j<=k[i];j++)
w[i]=w[i]*10;
for(i=1;i<=q;i++)
{
for(l=1;l<=n;l++)
{
if(a[l]%w[i]==b[i])
{
cout<<a[l]<<endl;
break;
}
else if(l==n)
cout<<"-1"<<endl;
}
}
return 0; }
by foxdemon @ 2019-06-01 11:42:18
#include<bits/stdc++.h>
using namespace std;
int n ;//书数量
int q ;//读者数量
int b[10005] ;//书码
int r[10005] ;//需求码
int l[10005] ;//长度
long long s ;
bool flag ;
int main()
{
cin >> n >> q ;
for ( int i = 1 ; i <= n ; i++ )
{
cin >> b[i] ;
}
sort ( b + 1 , b + n + 1 ) ;
for ( int i = 1 ; i <= q ; i++ )
{
flag = 0 ;
cin >> l[i] >> r[i] ;
long long s = pow ( 10 , l[i] ) ;
for ( int j = 1 ; j <= n ; j++ )
{
if ( b[j] % s == r[i] )
{
cout << b[j] << endl ;
flag = 1 ;
break ;
}
}
if ( flag == 0 )
{
cout << "-1" << endl ;
}
}
return 0;
}
by foxdemon @ 2019-06-01 11:43:05
字符串解法
#include<bits/stdc++.h>
using namespace std ;
string s[1005] ;
string x ;
int n , q , l ;
bool flag , flag1 ;
bool com( string a , string b )
{
int len1 = a.size() ;
int len2 = b.size() ;
if ( len1 == len2 ) return a < b ;
return len1 < len2 ;
}
int main()
{
cin >> n >> q ;
for ( int i = 1 ; i <= n ; i++ )
{
cin >> s[i] ;
}
sort ( s + 1 , s + 1 + n , com ) ;
for ( int i = 1 ; i <= q ; i++ )
{
cin >> l >> x ;
flag1 = 0 ;
for ( int j = 1 ; j <= n ; j++ )
{
flag = 0 ;
int len = s[j].size() - 1 ;
for ( int k = l - 1 ; k >= 0 ; k-- , len-- )
{
if ( x[k] != s[j][len] )//不成立
{
flag = 1 ;
break ;
}
}
if ( flag == 0 )//如果成立
{
flag1 = 1 ;
cout << s[j] << endl ;//输出
break ;
}
}
if ( flag1 == 0 )//如果没有
{
cout << -1 << endl ;
}
}
return 0 ;
}
by foxdemon @ 2019-06-01 11:43:41
@001__c 您康康,应该是差不多的,应该找的到bug辽QWQ