标签:位置 活跃 font cout ase 空格 head string erase
1 #include <iostream> 2 #include <malloc.h> 3 using namespace std; 4 typedef struct list{ 5 struct list *next; 6 int elem; 7 } list ; 8 9 int main() 10 { 11 int n; 12 int i; 13 list *head; 14 list *p; 15 while(cin>>n) 16 { 17 p = (list*)malloc(sizeof(list)); 18 p ->elem = 1; 19 head = p; 20 for(i = 2;i<=n;i++) 21 { 22 p->next = (list*)malloc(sizeof(list)); 23 p->next ->elem = i; 24 p = p->next; 25 } 26 p->next = head; 27 p = head; 28 29 while(p ->next->next != p) 30 { 31 cout<<p->next->elem<<" "; 32 p->next = p->next->next; 33 p = p->next; 34 } 35 cout<<endl; 36 cout<<p->next->elem<<" "<<p->elem<<endl; 37 break; 38 } 39 return 0; 40 }
1 #include <iostream> 2 #include <vector> 3 #include <string> 4 #include <algorithm> 5 #include <set> 6 7 int main() 8 { 9 using namespace std; 10 int n; 11 while (cin >> n) { 12 set<int> arr; 13 for (int i = 0; i < n; i++) { 14 arr.insert(i + 1); 15 } 16 set<int>::iterator iter = arr.begin(); 17 iter++; 18 set<int>::iterator itor = iter; 19 while (arr.size() > 2) { 20 itor++; 21 if (itor == arr.end()) { 22 itor = arr.begin(); 23 itor++; 24 } 25 else if (++itor == arr.end()) { 26 itor = arr.begin(); 27 } 28 if(arr.size() > 3) 29 cout << *iter << " "; 30 else 31 cout << *iter << endl; 32 arr.erase(*iter); 33 iter = itor; 34 } 35 if (iter == arr.begin()) { 36 cout << *arr.begin() << " " << *arr.rbegin() << endl; 37 } 38 else { 39 cout << *arr.rbegin() << " " << *arr.begin() << endl; 40 } 41 } 42 return 0; 43 }
标签:位置 活跃 font cout ase 空格 head string erase
原文地址:http://www.cnblogs.com/qqky/p/6978088.html