Wang20280214 @ 2024-08-18 21:39:12
#include <bits/stdc++.h>
using namespace std;
int a[3],s,sum,aac,bbc,ccc;
int ac,bc,cc;
int main()
{
cin>>a[0]>>a[1]>>a[2];
getchar();
ac=getchar()-'A';
bc=getchar()-'A';
cc=getchar()-'A';
sort(a,a+3);
cout<<a[ac]<<" "<<a[bc]<<" "<<a[cc];
}
by jza110228 @ 2024-08-18 21:46:05
这样子就行
#include<bits/stdc++.h>
using namespace std;
int a[3];
string s;
int main(){
cin>>a[0]>>a[1]>>a[2];
cin>>s;
sort(a,a+3);
cout<<a[s[0]-'A']<<" "<<a[s[1]-'A']<<" "<<a[s[2]-'A'];
return 0;
}
@Wang20280214
by __Real_Madrid__ @ 2024-08-18 21:47:15
@Wang20280214 你也可以把每一种情况列出来
by __Real_Madrid__ @ 2024-08-18 21:48:18
@Wang20280214
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;
int main()
{
string s;
int a,b,c;
cin>>a>>b>>c;
cin>>s;
int len=s.length();
if(s[0]=='A'&&s[1]=='B'&&s[2]=='C')
{
if(a>b&&b>c) cout<<c<<" "<<b<<" "<<a;
if(a>c&&c>b) cout<<b<<" "<<c<<" "<<a;
if(b>a&&a>c) cout<<c<<" "<<a<<" "<<b;
if(b>c&&c>a) cout<<a<<" "<<c<<" "<<b;
if(c>a&&a>b) cout<<b<<" "<<a<<" "<<c;
if(c>b&&b>a) cout<<a<<" "<<b<<" "<<c;
}
else if(s[0]=='A'&&s[1]=='C'&&s[2]=='B')
{
if(a>b&&b>c) cout<<c<<" "<<a<<" "<<b;
if(a>c&&c>b) cout<<b<<" "<<a<<" "<<c;
if(b>a&&a>c) cout<<c<<" "<<b<<" "<<a;
if(b>c&&c>a) cout<<a<<" "<<b<<" "<<c;
if(c>a&&a>b) cout<<b<<" "<<c<<" "<<a;
if(c>b&&b>a) cout<<a<<" "<<c<<" "<<b;
}
else if(s[0]=='B'&&s[1]=='A'&&s[2]=='C')
{
if(a>b&&b>c) cout<<b<<" "<<c<<" "<<a;
if(a>c&&c>b) cout<<c<<" "<<b<<" "<<a;
if(b>a&&a>c) cout<<a<<" "<<c<<" "<<b;
if(b>c&&c>a) cout<<c<<" "<<a<<" "<<b;
if(c>a&&a>b) cout<<a<<" "<<b<<" "<<c;
if(c>b&&b>a) cout<<b<<" "<<a<<" "<<c;
}
else if(s[0]=='B'&&s[1]=='C'&&s[2]=='A')
{
if(a>b&&b>c) cout<<b<<" "<<a<<" "<<c;
if(a>c&&c>b) cout<<c<<" "<<a<<" "<<b;
if(b>a&&a>c) cout<<a<<" "<<b<<" "<<c;
if(b>c&&c>a) cout<<c<<" "<<b<<" "<<a;
if(c>a&&a>b) cout<<a<<" "<<c<<" "<<b;
if(c>b&&b>a) cout<<b<<" "<<c<<" "<<a;
}
else if(s[0]=='C'&&s[1]=='A'&&s[2]=='B')
{
if(a>b&&b>c) cout<<a<<" "<<c<<" "<<b;
if(a>c&&c>b) cout<<a<<" "<<b<<" "<<c;
if(b>a&&a>c) cout<<b<<" "<<c<<" "<<a;
if(b>c&&c>a) cout<<b<<" "<<a<<" "<<c;
if(c>a&&a>b) cout<<c<<" "<<b<<" "<<a;
if(c>b&&b>a) cout<<c<<" "<<a<<" "<<b;
}
else if(s[0]=='C'&&s[1]=='B'&&s[2]=='A')
{
if(a>b&&b>c) cout<<a<<" "<<b<<" "<<c;
if(a>c&&c>b) cout<<a<<" "<<c<<" "<<b;
if(b>a&&a>c) cout<<b<<" "<<a<<" "<<c;
if(b>c&&c>a) cout<<b<<" "<<c<<" "<<a;
if(c>a&&a>b) cout<<c<<" "<<a<<" "<<b;
if(c>b&&b>a) cout<<c<<" "<<b<<" "<<a;
}
return 0;
}
by haimingbei @ 2024-08-18 21:48:30
@Wang20280214 简单粗暴(求关注)
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,c;
string q;
cin>>a>>b>>c;
cin>>q;
int maxx=max(a,max(b,c));
int minn=min(a,min(b,c));
int middle;
if(a!=maxx && a!=minn)middle=a;
else if(b!=maxx && b!=minn)middle=b;
else if(c!=maxx && c!=minn)middle=c;//先确定三个数的大小
//全排列6种情况,直接枚举
if(q[0]=='A' && q[1]=='B' && q[2]=='C')cout<<minn<<" "<<middle<<" "<<maxx;
else if(q[0]=='A' && q[1]=='C' && q[2]=='B')cout<<minn<<" "<<maxx<<" "<<middle;
else if(q[0]=='B' && q[1]=='A' && q[2]=='C')cout<<middle<<" "<<minn<<" "<<maxx;
else if(q[0]=='B' && q[1]=='C' && q[2]=='A')cout<<middle<<" "<<maxx<<" "<<minn;
else if(q[0]=='C' && q[1]=='A' && q[2]=='B')cout<<maxx<<" "<<minn<<" "<<middle;
else if(q[0]=='C' && q[1]=='B' && q[2]=='A')cout<<maxx<<" "<<middle<<" "<<minn;
return 0;
}
by Wang20280214 @ 2024-08-18 21:49:08
@jza110228 已关注 感谢回复
by haimingbei @ 2024-08-18 21:49:25
@__Real_Madrid__ 代码也可以稍微变短一点(如上)
by Wang20280214 @ 2024-08-18 21:49:32
@__Real_Madrid__ 已关注 感谢回复
by jza110228 @ 2024-08-18 21:49:59
@Wang20280214 数据不是从大到小排序
by __Real_Madrid__ @ 2024-08-18 21:50:28
@haimingbei 有道理
by Wang20280214 @ 2024-08-18 21:50:56
@haimingbei 已关注 感谢回复