无输出

P1424 小鱼的航程(改进版)

死循环了: ``` #include<iostream> using namespace std; int main() { long long n,x,s=0,i; cin>>x>>n; for(i=x;i<=i+n;i++) { //这里,i<=i+n死循环 if ((i%6!=0)&&(i%7!=0)) s=s+250; } cout<<s; return 0; } ```
by brealid @ 2018-07-15 11:03:30


@[刘素质](/space/show?uid=102028) ```cpp for(i=x;i<=i+n;i++) ``` 有输出才奇怪。
by Nero_Claudius @ 2018-07-15 11:04:00


@[DARTH_VADER](/space/show?uid=38859) 为什么。。
by 初嫁QAQ @ 2018-07-15 11:31:16


@[DARTH_VADER](/space/show?uid=38859) 我蒟蒻
by 初嫁QAQ @ 2018-07-15 11:31:31


@[刘素质](/space/show?uid=102028) 每一次循环上限都会增加1 ```cpp i<=i+n ``` 那么永远不会结束。 应该改为: ```cpp i<=n ```
by Nero_Claudius @ 2018-07-15 11:34:04


@[DARTH_VADER](/space/show?uid=38859) 可是那是星期几啊,。。
by 初嫁QAQ @ 2018-07-15 11:55:30


@[刘素质](/space/show?uid=102028) 具体题目是什么不清楚。。。懒得看题了 总之源代码那样是肯定会爆的
by Nero_Claudius @ 2018-07-15 12:10:35


@[刘素质](/space/show?uid=102028) 正解: ```cpp for(int i=0;i<n;i++){ if((x!=6)&&(x!=7))s+=250; if(x==7)x=1; else x++; } ```
by Nero_Claudius @ 2018-07-15 12:12:29


@[DARTH_VADER](/space/show?uid=38859) 谢谢
by 初嫁QAQ @ 2018-07-15 12:17:30


i<=i+n,不论是数学上还是代码上,只要n>=0,这就是永远成立的。。。
by 1124828077ccj @ 2018-07-15 13:11:57


|