【发布时间】:2016-03-28 05:44:41
【问题描述】:
int main()
{
long int n,x,cost[100];
cin>>n>>x;
for(int i=0;i<n;i++)
cin>>cost[i];
int i=0,flag=0,s=0,first;
first=cost[0];
while(i<n)
{
s+=cost[i];
if(s>x){
s-=first;
first++;
}
if(s==x)
{
flag=1;
break;
}
i++;
}
if(flag==0) cout<<"no";
else cout<<"yes";
}
此代码是来自hackerearth 的问题。问题的名称是“Prateek 和他的朋友们” 请帮忙。
【问题讨论】:
-
想想如果唯一的输入是“文件结尾”会发生什么,这就是在 Ideone 中没有标准输入时会发生什么。你认为你的变量会有什么价值?
-
顺便说一句,您尝试过的不仅仅是 one 琐碎的测试用例吗?
-
如果
n > 100呢?