1 #include<iostream> 2 #include<vector> 3 #include<map> 4 5 using namespace std; 6 7 bool compare(int a, int b) 8 { 9 return a > b; 10 } 11 12 int main() 13 { 14 int n, cnt = 0; 15 int value; 16 map<int, int, bool(*)(int,int)> m(compare); 17 cin >> n; 18 while (cnt != n) 19 { 20 ++cnt; 21 cin >> value; 22 if (m.find(value) == m.end()) 23 m[value] = 0; 24 while (value != 1) 25 { 26 if (value % 2 == 0) 27 value /= 2; 28 else 29 value = (3 * value + 1) / 2; 30 ++m[value]; 31 } 32 } 33 bool flag = 0; 34 for(auto iter = m.begin(); iter != m.end(); ++iter) 35 if (iter->second == 0) 36 { 37 cout << (flag == 0 ? "" : " ") << iter->first; 38 flag = 1; 39 } 40 41 system("pause"); 42 return 0; 43 }
原文:https://www.cnblogs.com/Huayra/p/12162945.html