Wendy_Hello_qwq @ 2024-12-09 21:37:09
#include <iostream>
#include <algorithm>
using namespace std;
int n, q;
long long a[1007], book[1007], len[1007], read[1007];
int main() {
cin >> n >> q;
for (int i = 1; i <= 1007; i++)
a[i] = 1;
for (int i = 1; i <= n; i++)
cin >> book[i];
sort (book, book + n + 1);
for (int i = 1; i <= q; i++) {
cin >> len[i] >> read[i];
for (int j = 1; j <= len[i]; j++)
a[i] *= 10;
}
for (int i = 1; i <= q; i++) {
for (int j = 1; j <= n; j++) {
if (book[j] % a[i] == read[i]) {
cout << book[j] << endl;
break;
} else if (j == n) {
cout << "-1" << endl;
break;
}
}
}
return 0;
}
显示Wrong Answer.wrong answer Too short on line 1.
,改了好多次了,求调QwQ。
by Wendy_Hello_qwq @ 2024-12-09 21:38:32
教 -> 交
by Mengchen_Yxf2013_qwq @ 2024-12-09 21:46:18
我的代码:
#include <bits/stdc++.h>
using namespace std;
int n, q;
int a[1100];
int main() {
scanf ("%d%d", &n, &q);
for (int i = 1; i <= n; i++)
scanf ("%d", &a[i]);
for (int i = 1; i <= q; i++) {
int l, b;
scanf ("%d%d", &l, &b);
int p = 1;
for (int j = 0; j < l; j++)
p *= 10;
int ans = -1;
for (int j = 1; j <= n; j++)
if (a[j] % p == b)
if (ans == -1 || a[j] < ans)
ans = a[j];
printf ("%d\n", ans);
}
return 0;
}
by Mengchen_Yxf2013_qwq @ 2024-12-09 21:46:35
@Wendy_Hello_qwq
by wjr_jok @ 2024-12-09 22:18:29
@Wendy_Hello_qwq 第一个循环访问越界了。唐。
by Wendy_Hello_qwq @ 2024-12-10 19:43:53
@Mengchen_Yxf2013_qwq 谢谢你的代码
by Wendy_Hello_qwq @ 2024-12-10 19:44:08
@wjr_jok 感谢,果然是循环越界
by Wendy_Hello_qwq @ 2024-12-10 19:44:22
此贴结