竞赛
考级
你被骗了(doge )
题解
第一种:(普通函数) 第二种:(Lambda表达式) 都是函数,只不过两种不一样
这道题很简单,我用的是Lambda表达式:
其实很简单
我使用sort排序,用C语言的输入输出加速。 (20ms)
自己看怎么写 代码:
> O(N)O(N) O(N)
#include <iostream> #include <bits/stdc++.h> using namespace std; using ll = long long; int n,a[100010]; bool cmp( int x, int y ) { int u = x % 10; int v = y % 10; if( u != v ) return u > v; else return x < y; } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for(int i = 0; i < n; i++) cin >> a[i]; sort( a, a + n, cmp ); for(int i = 0; i < n; i++) cout << a[i] << endl; return 0; }
#include <iostream> #include <algorithm> using namespace std; int b[100005]; bool cmp(int x, int y) { if (x % 10 != y % 10) return x % 10 > y % 10; // 个位数大的在前 return x < y; // 个位数相同,数字小的在前 } int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> b[i]; }
提交答案之后,这里将显示提交结果~