2 条题解
-
1
这是60分代码,思路没什么可解释的
#include <bits/stdc++.h> #define ll long long using namespace std; ll n, a[1005]; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; sort (a + 1, a + n + 1); for (int i = 1; i <= n; i++) cout << a[i] << " "; return 0; }
以下是AC代码,也没啥好解释的:
#include <bits/stdc++.h> using namespace std; int n; bool cmp(string x, string y) { if (x.length() != y.length()) return x.length() < y.length(); return x < y; } int main() { int i = 0; string a[1005]; for (cin >> n; n; --n) cin >> a[++i]; sort (a + 1, a + i + 1, cmp); int cnt = i; for (i = 1; i <= cnt; i++) cout << a[i] << " "; return 0; }
-
1
yasuo👀️
确实有点难
#include <iostream> #include <algorithm> #include <string> int yasuo(std::string a,std::string b){ if(a.length()==b.length())return a<b; return a.length()<b.length();} int main(){ int n; std::string a[1005]; std::cin>>n; for(int i=0;i<n;i++)std::cin>>a[i]; std::sort(a,a+n,yasuo); for(int i=0;i<n;i++)std::cout<<a[i]<<" "; return 0;}
- 1
信息
- ID
- 473
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 7
- 标签
- 递交数
- 45
- 已通过
- 12
- 上传者