weixin_44019404
2018-12-22 19:52
采纳率: 66.7%
浏览 417

uva 11922 为什么一直答案错误

#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条回答 默认 最新

  • weixin_44019404 2018-12-26 03:47
    已采纳

    谢谢我自己 弄明白了哦

    点赞 评论
  • blownewbee 2018-12-22 15:07

    你的程序代码都没贴对,就不看了,参考下这个吧:https://blog.csdn.net/u013480600/article/details/24426803

    点赞 评论

相关推荐 更多相似问题