小编Ahm*_*sen的帖子

while(cin)和while(cin >> num)之间的区别是什么

以下两个循环和每个循环何时停止有什么区别?

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
    int x,y;
    while(cin >> x){
        // code
    }
    while(cin){
        cin >> y;
        //code
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ iostream

16
推荐指数
2
解决办法
3万
查看次数

重复减去值的代码有多复杂?

我有这个代码,想知道它的时间复杂度:

    int N,M; // let N and M be any two numbers 
    while(N != M && N > 0 && M > 0){
       if(N > M)N -= M;
       else M -= N;
    }
Run Code Online (Sandbox Code Playgroud)

我不知道如何分析这个,因为M和N的值以不寻常的方式减少.有没有一种标准的方法来解决这个问题?

c++ algorithm complexity-theory big-o time-complexity

-1
推荐指数
1
解决办法
97
查看次数