Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- int main()
- {
- ifstream fin("numere.in");
- int na,nb;
- cin>>na>>nb;
- int nra[100];
- int nrb[100];
- int x;
- int k=0;
- for(int i=0; i<=100; i++)
- {
- nra[i]=0;
- nrb[i]=0;
- }
- for(int i=1; i<=na; i++)
- {
- fin>>x;
- if(x%100/10==0)
- {
- nra[x%10*10+x%100/10]++;
- }
- else
- {
- nra[x%100]++;
- }
- }
- for(int i=1; i<=nb; i++)
- {
- cin>>x;
- if(x%100/10==0)
- {
- nrb[x%10*10+x%100/10]++;
- }
- else
- {
- nrb[x%100]++;
- }
- }
- int j;
- for(int i=0; i<=100; i++)
- {
- j=i%10*10+i/10;
- if(i==j)
- {
- if(nra[i]!=0 && nrb[i]!=0)
- {
- k+=nra[i]*nrb[i];
- nra[i]=0;
- nrb[i]=0;
- }
- }
- else
- {
- if((nra[i]!=0 ||nra[j]!=0)&&(nrb[i]!=0||nrb[j]!=0))
- {
- k+=(nra[i]+nra[j])*(nrb[i]+nrb[j]);
- nra[i]=0;
- nra[j]=0;
- nrb[i]=0;
- nrb[j]=0;
- }
- }
- }
- cout<<k;
- fin.close();
- return 0;
- }
- //9 7
- //112 20 42 112 5013 824 10012 55 155
- //402 1024 321 521 57 6542 255
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement