赞
踩
**
**
**
**
#include <iostream> #include <vector> int main() { std::vector<int> a {1, 3, 14, 25, 31, 32, 58, 73, 98, 105}; int x{}; std::cin >> x; int* pa = &a[0]; for (int i = 0; i < 11; i++) { if ((a [0]>a[1]&&x > * pa)|| (a[0] < a[1] && x < * pa))//(大神写法^:规则0^0=0 0^1=1 1^0=1 1^1=0)(a[0]>a[1])^(x < * pa) { a.insert(a.begin()+i,x); break; } pa++; } for (int i :a) { std::cout << i << "\n"; } }
**
**
**
**
#include <iostream> int main() { int zxsort[5]{125,94,85,21,5}; int dxsort[5]{ 5,21,85,94,125 }; int* rsort; int a; bool iszx{ dxsort[0] > dxsort[1] }; rsort = (int*)malloc(6 * sizeof(int)); memcpy(rsort, dxsort, 5 * sizeof(int)); int count = 6; do { std::cin >> a; for (int i = 0; i < count; i++) { if (iszx ^ (rsort[i] > a)) { int b = rsort[i]; rsort[i] = a; a = b; } else if (rsort[i] == a) { int b = rsort[i]; rsort[i] = a; a = b; } } for (int i = 0; i < count; i++) { std::cout << rsort[i] << std::endl; } ++count; rsort = (int*)realloc(rsort,count*sizeof(int) ); } while (a!=13); }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。