baojiaming01 @ 2023-01-25 16:34:04
#include<bits/stdc++.h>
using namespace std;
int a[1001],b[1001],c[1001],d[1001];
int main()
{
int n,q;
cin>>n>>q;
for(int i=1; i<=q; i++) cin>>a[i];
for(int i=1; i<=q; i++) cin>>b[i]>>c[i];
for(int i=1; i<=n; i++)
{
for(int j=1; j<=q; j++)
{
int ans=0,t=c[i]%10;
bool flag=false;
while(t!=0)
{
t=t%10;
if(t==c[i])
{
flag=true;
break;
}
}
if(b[i]==ans && flag==true) d[i]=a[i];
else d[i]=-1;
}
}
for(int i=1; i<=q; i++) cout<<d[i];
return 0;
}
by 20090416lrs @ 2023-01-25 17:02:45
你这个ans自定义以来都是零没变过啊
by 20090416lrs @ 2023-01-25 17:06:33
而且你这样双层循环怎么看都是超时的样子
by baojiaming01 @ 2023-01-25 17:08:25
改了,还是错的
#include<bits/stdc++.h>
using namespace std;
int a[1001],b[1001],c[1001],d[1001];
int main()
{
int n,q;
cin>>n>>q;
for(int i=1; i<=q; i++) cin>>a[i];
for(int i=1; i<=q; i++) cin>>b[i]>>c[i];
for(int i=1; i<=n; i++)
{
for(int j=1; j<=q; j++)
{
int ans=0,t1=c[i]%10,t2=a[i];
bool flag=false;
while(t2>0)
{
ans++;
t2=t2/10;
}
while(t1!=0)
{
t1=t1%10;
if(t1==c[i])
{
flag=true;
break;
}
}
if(b[i]==ans && flag==true) d[i]=a[i];
else d[i]=-1;
}
}
for(int i=1; i<=q; i++) cout<<d[i];
return 0;
}
不知道为啥我给删了
by baojiaming01 @ 2023-01-25 17:10:13
@20090416lrs 那咋办???是要把一个循环给删掉吗???
by 20090416lrs @ 2023-01-25 17:13:27
我个人认为第二个循环边输入边查找再输出可能比较好.(省一个循环,你试试吧)
by baojiaming01 @ 2023-01-25 17:20:29
额......好像还是超时了......
by 20090416lrs @ 2023-01-26 08:32:19
超了一点还是很多?要不别暴搜,用二分试试
by 20090416lrs @ 2023-01-26 15:04:52
先排序就不会超时了