标签:
原题:
Description
Input
Output
Sample Input
Sample Output
1 #include<iostream> 2 #include<list> 3 #define lit list<int>::iterator 4 using namespace std; 5 list<int> soldier; 6 7 8 9 void delete2(list<int>&a) 10 { 11 lit it = a.begin(); 12 for (int i = 1; it != a.end(); it++,i++) 13 { 14 if ( i% 2 == 0) 15 { 16 *it = 6000; 17 } 18 } 19 } 20 21 22 void delete3(list<int>&a) 23 { 24 lit it = a.begin(); 25 for (int i = 1; it != a.end(); it++,i++) 26 { 27 if (i % 3 == 0) 28 { 29 *it = 6000; 30 } 31 } 32 } 33 34 35 int main() 36 { 37 int t; 38 cin >> t; 39 while (t--) 40 { 41 soldier.clear(); 42 int n; 43 cin >> n; 44 for (int i = 1; i <= n; i++) 45 { 46 soldier.insert(soldier.end(),i); 47 } 48 for (int i = 0;; i++) 49 { 50 if (soldier.size() <= 3) 51 { 52 break; 53 } 54 if (i % 2 == 0) 55 { 56 delete2(soldier); 57 soldier.remove(6000); 58 } 59 else 60 { 61 delete3(soldier); 62 soldier.remove(6000); 63 } 64 } 65 66 for (lit it = soldier.begin(); it != soldier.end(); it++) 67 { 68 if (it==soldier.begin()) 69 cout << *it; 70 else 71 { 72 cout << ‘ ‘ << *it; 73 } 74 } 75 cout << endl; 76 } 77 78 79 return 0; 80 }
标签:
原文地址:http://www.cnblogs.com/shawn-ji/p/4678401.html