FengYuXinMing @ 2023-08-10 10:49:35
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3+5;
int a[maxn];
int main(){
int n,m;
cin >> n >> m;
for (int i = 1;i <= n;i++){
cin >> a[i];
}
int x,y;
for (int i = 1;i <= m;i++){
int minn = 1e7+5;
cin >> x >> y;
if (x == 1){
for (int j = 1;j <= n;j++){
if (a[j]%10 == y%10){
minn = min(minn,a[j]);
}
}
}
for (int j = 1;j <= n;j++){
if ((a[j]-y)%10==0 && (a[j]-y) >= 0){
minn = min(minn,a[j]);
}
}
if (minn == 1e7+5)
cout << -1 << endl;
else
cout << minn << endl;
}
return 0;
}
by xxxxxzy @ 2023-08-10 10:54:32
用字符串存,long long存不下
by FengYuXinMing @ 2023-08-10 11:06:21
@C20252323tzy 所有的图书编码和需求码均 不超过
by xxxxxzy @ 2023-08-10 11:10:27
@ababbjxzt 不好意思看错题了。。
by FengYuXinMing @ 2023-08-10 11:10:46
@C20252323tzy emmm
by xxxxxzy @ 2023-08-10 11:19:22
@ababbjxzt
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3+5;
int a[maxn];
int main(){
int n,m;
cin >> n >> m;
for (int i = 1;i <= n;i++){
cin >> a[i];
}
int x,y;
for (int i = 1;i <= m;i++){
int minn = INT_MAX;
cin >> x >> y;
for (int j = 1;j <= n;j++){
if ((a[j]-y)%(int)pow(10,x)==0 && (a[j]-y) >= 0){
minn = min(minn,a[j]);
}
}
if (minn == INT_MAX)
cout << -1 << endl;
else
cout << minn << endl;
}
return 0;
}
已AC
by FengYuXinMing @ 2023-08-10 11:31:26
@C20252323tzy 谢谢