weixin_44019404
weixin_44019404
采纳率66.7%
2018-12-22 19:52 阅读 415

uva 11922 为什么一直答案错误

40

#include
#include
#include
int a[20000], b[20000];
int sum[20000];
int compare(const void a, const void *b)
{
return (
(int *)a - *(int *)b);
}
int main()
{

int n,m;
int i=0;
int count = 0;
scanf("%d %d", &n, &m);
getchar();
while (n != 0 && m != 0)
{
for ( i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
for ( i = 0; i < m; i++)
{
scanf("%d", &b[i]);
}
qsort(a, n, sizeof(int), compare);
qsort(b, m, sizeof(int), compare);
int temp=0;
if(n==1&&b[m-1]>=a[0])
{ for(i=0;i {
if(b[i]>=a[0]) {
sum[count]+=b[i];

    break;}
    }   count++;
    scanf("%d %d", &n, &m);
    getchar();
    continue;}
else if(n==1&&b[m-1]<a[0]){
    sum[count]=-1;
    count++;
    scanf("%d %d", &n, &m);
    getchar();
    continue;
    }
for(i=0;i<m;i++)
    {
        if(b[i]>=a[temp])
        {
            sum[count]+=b[i];
        }
        if(++temp==n) break;
    }
    if(temp<n)
    {
        sum[count]=-1;
    }
    count++;
    scanf("%d %d", &n, &m);
    getchar();
}
for(i=0;i<count;i++)
{if(sum[i]!=-1)
{
    printf("%d\n",sum[i]);
}
else printf("Loowater is doomed!\n");
}

// system("pause");
return 0;
}

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

相关推荐