Login
Register
Problem list
Online status
Huhu_Miao
:
2024-11-05 00:41:08
/** * author: Huhu_Miao * created: 2024.11.5 00:40:00 (UTC+8) **/ #include
void printVector(const std::vector
& vec){ for(const int & elem : vec){ std::cout << elem << ' '; } std::cout << '\n'; } void solve(){ int n; std::cin >> n; std::vector
vec(n,0); for(auto & elem : vec){ std::cin >> elem; } for(int i = 0 ; i < n ; i++){ bool flag = false; for(int j = 1 ; j < n-i ;j++){ if(vec[j] < vec[j-1]) std::swap(vec[j],vec[j-1]); flag = true; } printVector(vec); return; if(!flag) break; } } int main(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int T; std::cin>>T; while(T--){ solve(); } return 0; }
uptt-sn
:
2021-04-26 09:10:52
using namespace std; #include
int main() { int m; cin >> m; while ((m > 0) && (m < 100)) { int n; cin >> n; if (n > 1000 ){ while (n > 1000) { cin >> n; } } int *k = new int[n]; int p = 0; do { cin >> k[p]; p++; } while (p < n); int i = 0;int temp; while (k[i + 1] > 0) { if (k[i] > k[i + 1]) { temp = k[i + 1]; k[i + 1] = k[i]; k[i] = temp; } i++; } for (int q = 0;q < n;++q) { cout << k[q]<<; } m--; cout << endl; delete[]k; } system("pause"); return 0; } 在编译器上输出正确,不知道什么地方runtime error
Post Your Comment