Pagini recente » Monitorul de evaluare | Istoria paginii utilizator/dariuso | Statistici Iurciuc Andrei (andrei_suny) | Istoria paginii utilizator/ancav | Cod sursa (job #1036556)
#include<stdio.h>
#include<algorithm>
#include<cassert>
using namespace std;
FILE*f=fopen("dtcsu.in","r");
FILE*g=fopen("dtcsu.out","w");
int ch,sol;
const int n = 276997;
char buff[25];
long long A[100000];
int main () {
long long x = 0; int in = 0;
for ( int i = 1 ; i <= n ; ++i ){
fgets(buff,23,f);
x = 0;
ch = 0;
while ( buff[ch] >= '0' && buff[ch] <= '9' ){
x = x*10 + buff[ch]-'0';
++ch;
}
if ( x % 11 == 0 ) continue ;
A[++in] = x;
}
int q = 0;
fgets(buff,23,f); ch = 0;
while ( buff[ch] >= '0' && buff[ch] <= '9' ){
q = q*10 + buff[ch]-'0';
++ch;
}
assert(in<100000);
sort(A+1,A+in+1);
int left,middle,right;
for ( int i = 1 ; i <= q ; ++i ){
fgets(buff,23,f);
long long x = 0;
ch = 0;
while ( buff[ch] >= '0' && buff[ch] <= '9' ){
x = x*10 + buff[ch]-'0';
++ch;
}
if ( x == 0 ) continue ;
while ( x % 11 == 0 ) x /= 11;
left = 1,right = in;
while ( left <= right ){
middle = (left+right)>>1;
if ( A[middle] == x ){
++sol; break ;
}
if ( A[middle] < x ){
left = middle+1;
}
else{
right = middle-1;
}
}
}
fprintf(g,"%d\n",sol);
fclose(f);
fclose(g);
return 0;
}