能帮忙看看错在哪里了吗?

冥思苦想了很久,写出来的,虽然有点暴力,没有优化,但是连正确答案都算不出来...
有点小伤心(#@^@)
#include<iostream>
using namespace std;
int main()
{
int n=0;
int k=0;
int p=0;
int hotel_clour[n];
int cofe_price[n];
cin>>n>>k>>p;
for (int shuru=0;shuru<n;shuru++)
{
cin>>hotel_clour[shuru]>>cofe_price[shuru];
}

int ans=0;
for (int i=0;i<=n;i++)//"i" is the frist people
{
for (int j=0;j<=n;j++)//"j" is the second people
{
bool tu=0;
if (!(i==j))
{

if (hotel_clour[i]==hotel_clour[j])
{
if (i>j)
{
for (int we=j;we<i;we++)
{
if (cofe_price[we]<=p)
tu=1;
}
} else if (i<j)
{
for (int we=i;we<=j;we++)
{
if (cofe_price[we]<=p)
tu=1;
}
}
}
}
if (tu==1)ans++;
}
}
cout<<ans;
return 0;
}

1 条评论

  • @ 2015-10-22 19:43:04

    您这份代码能过编译也真是神奇,开了Wall也没卡住。代码中main函数里先int n=0然后又定义长度为n的数组,最终结果就是这两个数组的长度都是0,这可以用sizeof验证,您会发现sizeof(hotel_clour)和sizeof(cofe_price)的值都是0。也就是讲,程序运行过程中堆栈内存里根本不存在这两个数组,所以出现错误的答案是很自然的。

  • 1

信息

ID
1737
难度
6
分类
数据结构 | 单调队列 点击显示
标签
递交数
3860
已通过
1162
通过率
30%
被复制
8
上传者