- 三位数重新排列
答案
- 2025-3-30 20:02:11 @
三位数重新排列
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,a,b,c;
cin>>n;
a=n%10;
b=n/10%10;
c=n/100;
if(a>b) swap(a,b);
if(a>c) swap(a,c);
if(b>c) swap(b,c);
cout<<a*100+b*10+c;
return 0;
}
8 comments
-
张景 LV 8 @ 2025-5-17 10:09:59
#include<bits/stdc++.h> using namespace std; struct stu { int id; int a; int b; int c; int z; }; bool cmd(stu x, stu y) { if(x.z != y.z) return x.z > y.z; if(x.a != y.a) return x.a > y.a; return x.id < y.id; } int main() { stu s[1000]; int n; cin>>n; for(int i = 0; i < n; i++) { s[i].id = i + 1; cin >> s[i].a >> s[i].b >> s[i].c; s[i].z = 0; s[i].z += s[i].a; s[i].z += s[i].b; s[i].z += s[i].c; } sort(s,s+n,cmd); for(int i=0; i<5; i++) { cout<<s[i].id<<' '<<s[i].z<<endl; } return 0; }
-
2025-5-10 10:32:45@
#include<bits/stdc++.h> using namespace std; struct stu{ int s,id; }; bool cmp(stu x,stu y){ return x.s > y.s; } int n; stu s[105]; int main(){ cin>>n; for(int i=0;i<n;i++){ cin>>s[i].s; s[i].id=i+1; } sort(s,s+n,cmp); for(int i=0;i<n;i++){ cout<<s[i].id<<" "; } return 0; }
-
2025-5-10 9:52:20@
#include<bits/stdc++.h> using namespace std; struct stu{ int y,m,d; }; bool cmp(stu t,stu t2){ if(t.y!=t2.y) return t.y < t2.y; else if(t.m!=t2.m) return t.m < t2.m; else if(t.d!=t2.d) return t.d < t2.d; } stu s[1005]; int main(){ int n; char c; cin>>n; for(int i=0;i<n;i++){ cin>>s[i].m>>c>>s[i].d>>c>>s[i].y; } sort(s,s+n,cmp); for(int i=0;i<n;i++){ printf("%02d/%02d/%d\n",s[i].m,s[i].d,s[i].y); } return 0; }
-
2025-4-26 11:26:52@
#include<bits/stdc++.h> using namespace std; struct stu{ int y,m,d; }; bool cmp(stu t,stu t2){ if(t.y!=t2.y) return t.y < t2.y; else if(t.m!=t2.m) return t.m < t2.m; else if(t.d!=t2.d) return t.d < t2.d; } stu s[1005]; int main(){ int n; char c; cin>>n; for(int i=0;i<n;i++){ cin>>s[i].m>>c>>s[i].d>>c>>s[i].y; } sort(s,s+n,cmp); for(int i=0;i<n;i++){ printf("%02d/%02d/%d\n",s[i].m,s[i].d,s[i].y); } return 0; }
-
2025-4-19 11:09:00@
#include<bits/stdc++.h> using namespace std; int nin[200005]; bool cmp(int x,int y) { return x>y; } int main() { int n,b; cin>>n>>b; for(int i=0; i<n; i++) { cin>>nin[i]; } sort(nin,nin+n,cmp); int sum,k=0; for(int i=0; i<n; i++) { sum+=nin[i]; k++; if(sum>b) { cout<<k; return 0; } } }
-
2025-4-12 10:31:37@
#include<bits/stdc++.h> using namespace std; int nin[200005]; bool cmp(int x,int y){ return x>y; } int main(){ int n,b; cin>>n>>b; for(int i=0;i<n;i++){ cin>>nin[i]; } sort(nin,nin+n,cmp); int sum,k=0; for(int i=0;i<n;i++){ sum+=nin[i]; k++; if(sum>b){ cout<<k; return 0; } } }
-
2025-4-12 10:31:35@
#include<bits/stdc++.h> using namespace std; int nin[200005]; bool cmp(int x,int y){ return x>y; } int main(){ int n,b; cin>>n>>b; for(int i=0;i<n;i++){ cin>>nin[i]; } sort(nin,nin+n,cmp); int sum,k=0; for(int i=0;i<n;i++){ sum+=nin[i]; k++; if(sum>b){ cout<<k; return 0; } } }
-
2025-3-30 20:03:32@
千钱买千鸡
#include<bits/stdc++.h> using namespace std; int main(){ int a,b,c,d; cin>>a>>b>>c>>d; for(int i=0;i<=1000/a;i++) { for(int j=0;j<=1000/b;j++) { for(int k=0;k<=1000/c;k++) { int l=1000-i-k-j; if(l+i+j+k==1000&&i*a+j*b+k*c+l*1.0/d==1000){ cout<<i<<' '<<j<<' '<<k<<' '<<l; return 0; } } } } cout<<"-i"; return 0; }
- 1
Information
- ID
- 2593
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 6
- Tags
- # Submissions
- 47
- Accepted
- 16
- Uploaded By