fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. char tb[]="1234567";
  8. for(unsigned nr=0;;++nr)
  9. {
  10. unsigned NR=0,fact=1,mul=0;
  11. for(char *w=tb+5;w>=tb;--w)
  12. {
  13. unsigned less=0;
  14. for(char *v=tb+6;v>w;--v) if(*v<*w) ++less;
  15. NR+=less*(fact*=(++mul));
  16. }
  17. if(NR!=nr) cout<<NR<<"!="<<nr<<endl; // only if unsigned overflow
  18. if(!next_permutation(tb,tb+7)) break;
  19. }
  20. cout<<"END"<<endl;
  21. return 0;
  22. }
Success #stdin #stdout 0s 2896KB
stdin
Standard input is empty
stdout
END