zhengweihao @ 2024-08-14 12:21:31
#include<bits/stdc++.h>
using namespace std;
int main()
{
int x,y,z;
cin>>x>>y>>z;
int a=0,b=0,c=0;
if(x<y&&x<z){
a=x;
if(y<z)
{
b=y;
c=z;
}
else
{
b=z;
c=y;
}
}
else if(y<x&&y<z){
a=y;
if(x<z){
b=z;
c=x;
}
else{
b=z;
c=x;
}
}
else {
a=z;
if(y<x){
b=y;
c=x;
}
else{
b=x;
c=y;
}
}
char a1,b1,c1;
cin>>a1>>b1>>c1;
if(a1=='A') cout<<a<<" ";
else if(a1=='B') cout<<b<<" ";
else if(a1=='C') cout<<c<<" ";
if(b1=='A') cout<<a<<" ";
else if(b1=='B') cout<<b<<" ";
else if(b1=='C') cout<<c<<" ";
if(c1=='A') cout<<a<<" ";
else if(c1=='B') cout<<b<<" ";
else if(c1=='C') cout<<c<<" ";
return 0;
}
by goIdie @ 2024-08-14 12:28:49
@zhengweihao ,建议这样写
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
string s;
int max_i=0,mid_i=0,min_i=0,a[3]={0},n[3]={0};
cin>>a[0]>>a[1]>>a[2]>>s;
for(int i=0;i<3;i++)
{
if(s[i]=='C')max_i=i;
else if(s[i]=='B')mid_i=i;
else if(s[i]=='A')min_i=i;
}
n[max_i]=max(a[0],max(a[1],a[2]));
n[min_i]=min(a[0],min(a[1],a[2]));
for(int i=0;i<3;i++)if(a[i]!=n[max_i]&&a[i]!=n[min_i])n[mid_i]=a[i];
for(int i=0;i<3;i++)cout<<n[i]<<" ";
return 0;
}
by 奈芙蓮 @ 2024-08-14 12:45:24
hack
2 1 3
ACB
by _____QWQ_____ @ 2024-08-14 13:05:11
可以排序+映射(有点小题大做了)
但码量挺少的 @zhengweihao
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,a[3];
map<char,int> mp;
for(int i=0;i<3;i++) cin>>a[i];
sort(a,a+3);
mp['A']=a[0];
mp['B']=a[1];
mp['C']=a[2];
char c;
for(int i=0;i<3;i++)
{
cin>>c;
cout<<mp[c]<<" ";
}
return 0;
}