PAT (Advanced Level) 1029. Median (25)

scanf读入居然会超时...用了一下输入挂才AC...

#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<queue>
#include<iostream>
#include<algorithm>
using namespace std; const int maxn=+;
int a[maxn],b[maxn];
int n1,n2; inline bool scan_d(int &num)
{
char in;bool IsN=false;
in=getchar();
if(in==EOF) return false;
while(in!='-'&&(in<''||in>'')) in=getchar();
if(in=='-'){ IsN=true;num=;}
else num=in-'';
while(in=getchar(),in>=''&&in<=''){
num*=,num+=in-'';
}
if(IsN) num=-num;
return true;
} int MIN(int a,int b)
{
if(a<b) return a;
return b;
} int main()
{
scanf("%d",&n1);
for(int i=;i<=n1;i++) scan_d(a[i]);
scanf("%d",&n2);
for(int i=;i<=n2;i++) scan_d(b[i]); int sz=; int p1=,p2=;
a[n1+]=,b[n2+]=; while(sz<n1+n2)
{
sz++;
int tmp1=a[p1],tmp2=b[p2];
if(tmp1<tmp2) p1++; else p2++;
if(sz==(n1+n2+)/)
{
printf("%d\n",MIN(tmp1,tmp2));
break;
}
}
return ;
}
上一篇:WPF中的WebBrowser


下一篇:Selenium IDE 3.6 命令Command详解