john11 @ 2020-06-13 20:51:12
//john11
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
long long int readnum, codenum;
long long int min = 0x7fffffffffffffff;
int main(void)
{
long long int i, j;
long long int lreadiss, lreadcode, lcode;
long long int *codes, *readiss, *readcode;
scanf("%lld %lld", &readnum, &codenum);
codes = malloc(codenum * sizeof(long long int) + 1);
for(i = 0; i < codenum; i++) {
scanf("%lld", &codes[i]);
}
readiss = malloc(readnum * sizeof(long long int) + 1);
readcode = malloc(readnum * sizeof(long long int) + 1);
for(i = 0; i < readnum; i++) {
scanf("%lld %lld", &readiss[i], &readcode[i]);
}
for(i = 0; i < readnum; i++) {
lreadiss = readiss[i];
lreadcode = readcode[i];
for(j = 0; j < codenum; j++) {
lcode = codes[j];
if(lcode % (long long int)pow(10, lreadiss) == lreadcode) {
if(lcode < min) {
min = lcode;
}
} else if(j == codenum-1) {
if(min == 0x7fffffffffffffff) {
printf("-1\n");
} else {
printf("%lld\n", min);
min = 0x7fffffffffffffff;
}
}
}
}
free(codes);
free(readiss);
free(readcode);
return 0;
}
by JRzyh @ 2020-06-13 20:53:17
好久没见用malloc的人了
by shao_qian @ 2020-06-13 20:53:49
写得好复杂
我的思路:sort+取模匹配
by john11 @ 2020-06-13 20:58:51
@Zhaoyuhang2008 数值范围太大, 我省着用内存
by fzj2007 @ 2020-06-13 21:28:31
@john11 这写法有毒吧?
by fzj2007 @ 2020-06-13 21:28:50
@john11 一般