Advertisement
heranchris0430

約瑟夫

Mar 17th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <stdlib.h>
  4.  
  5. using namespace std;
  6.  
  7. int main(){
  8.     while(1){
  9.         int m, n, k, b = 0, i[] = {0};
  10.  
  11.         while (1) {
  12.             cout << "約瑟夫:";
  13.             cin >> m >> n >> k;
  14.             for (int a = 1; a <= m; a++) {
  15.                 i[a] = { a };
  16.             }
  17.             for (int x = 0; x < k; x++) {
  18.                 i[n] = { 0 };
  19.                
  20.                 if (n > m) {
  21.                     n = 1;
  22.                     goto end;
  23.                 }
  24.             end:
  25.                 n += 2;
  26.             }
  27.             cout << i[n] << endl;
  28.         }
  29.  
  30.     system("PAUSE");
  31.     system("CLS");
  32.     }
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement