wzxujiacheng__ @ 2024-10-07 13:54:25
#include<bits/stdc++.h>
using namespace std;
int a[3];
char s[3];
bool cmp(int x,int y){return x<y;}
int read(){
int ret=0,f=1;char ch=getchar();
while (!isdigit(ch)) {if (ch=='-')f=-f;ch=getchar();}
while (isdigit(ch)) ret=(ret<<3)+(ret<<1)+(ch&15),ch=getchar();
return ret*f;
}
int main(){
for(int i=0;i<3;i++)a[i]=read();
for(int i=0;i<3;i++)scanf("%c",&s[i]);
sort(a+1,a+4,cmp);
for(int i=0;i<3;i++)printf("%d ",a[s[i]-'A']);
return 0;
}
by craftmine @ 2024-10-07 13:58:44
@wzxujiacheng__ 你的数组下标是0~2,排序时怎么变成了1~3???
by craftmine @ 2024-10-07 14:00:33
有分的话你就可以请管理加强数据了
by sdjjdjdjdjd @ 2024-10-07 14:03:05
略
int main(){
for(int i=0;i<3;i++)a[i]=read();
getchar();//滤掉换行,防止后面读到换行
for(int i=0;i<3;i++)scanf("%c",&s[i]);
略
}
by sdjjdjdjdjd @ 2024-10-07 14:03:44
还要把sort(a+1,a+4)改为sort(a,a+3)
by rain_wu @ 2024-10-07 14:06:17
#include <bits/stdc++.h>
using namespace std;
int main(){
int a[4];
char c[4];
cin>>a[1]>>a[2]>>a[3]>>c[1]>>c[2]>>c[3];
sort(a+1,a+3+1);
for(int i = 1;i<=3;i++){
if(c[i]=='A') cout<<a[1]<<' ';
else if(c[i]=='B')cout<<a[2]<<' ';
else if(c[i]=='C')cout<<a[3]<<' ';
}
return 0;
}
by rain_wu @ 2024-10-07 14:06:37
可以直接输入,然后for判断
by craftmine @ 2024-10-07 14:09:33
@wzxujiacheng__ 你的做法挺聪明的,我做时思路和@rain_wu 一样(以后用sort排序要小心)
by wzxujiacheng__ @ 2024-10-07 14:09:35
@craftmine @sdjjdjdjdjd @rain_wu 谢谢!
by wzxujiacheng__ @ 2024-10-07 14:17:52
@rain_wu @craftmine @sdjjdjdjdjd AC记录