Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
看了n遍 老是wa 。。。大家帮忙帮我看看#include <iostream> #include <memory.h> using namespace std; int main() { int t; scanf("%d",&t); while (t--) { int i,n,m,a[101],k=-1,l=-1; int p,e1=0,big1=0,e2=0,e3=0,e4=0,big2=0; memset(a,0,sizeof(a)); scanf("%d%d",&n,&m); for(i=0;i<n;i++) { scanf("%d",&a[i]); } p=a[m]; for(i=0;i<=m;i++) { if(a[i]>p) { big1=big1+1; l=i; } if(a[i]==p) e1=e1+1; } for(i=m;i<n;i++) { if(a[i]>p) { big2=big2+1; k=i; } if(a[i]==p) e2=e2+1; } if(k>=0){ for(i=k;i<n;i++) { if(a[i]==p) e3=e3+1; } } if(l>=0){ for(i=l;i<=m;i++) { if(a[i]==p) { e4=e4+1; } } } if(big1>0&&big2>0) printf("%d\n",big1+big2+e1+e3); if(big1>0&&big2==0) printf("%d\n",big1+e4); if(big1==0&&big2==0) printf("%d\n",e1); if(big1==0&&big2>0) printf("%d\n",e1+big2+e3); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator