相关疑难解决方法(0)

345
推荐指数
9
解决办法
31万
查看次数

为什么std :: cout这么耗时?

我已经制作了一个程序来计算8个字符串"sharjeel"的排列.

#include <iostream>
#include <time.h>

char string[] = "sharjeel";
int len = 8;
int count = 0;

void swap(char& a, char& b){
    char t = a;
    a = b;
    b = t;
}
void permute(int pos) {
    if(pos==len-1){
        std::cout << ++count << "\t" << string << std::endl;
        return;
    }
    else {
        for (int i = pos; i < len;i++)
        {
            swap(string[i], string[pos]);
            permute(pos + 1);
            swap(string[i], string[pos]);
        }
    }
}

int main(){
    clock_t start = clock();
    permute(0);
    std::cout << "Permutations: …
Run Code Online (Sandbox Code Playgroud)

c++ c++11

5
推荐指数
1
解决办法
2802
查看次数

标签 统计

c++ ×2

c++11 ×1

cout ×1

iostream ×1

printf ×1

stdio ×1