QWlanren @ 2024-10-08 18:15:19
改了半天还是全wa 已经改成最一目了然的代码了 但还是找不出问题
#include<iostream>
using namespace std;
int main()
{
int swap;
int A,B,C;
cin>>A>>B>>C;
if(A>B)
{
swap=A;
A=B;
B=swap;
}
if(B>C)
{
swap=B;
B=C;
C=swap;
}
if(A>B)
{
swap=B;
B=A;
A=swap;
}
char s[3];
scanf("%s",&s);
if(s[0]=='A')
{
cout<<A<<" ";
if(s[1]=='B')
{
cout<<B<<" "<<C<<" ";
}
else
{
cout<<C<<" "<<B<<" ";
}
}
else if(s[0]=='B')
{
cout<<B<<" ";
if(s[1]=='A')
{
cout<<A<<" "<<C<<" ";
}
else
{
cout<<C<<" "<<A<<" ";
}
}
else
{
cout<<C<<" ";
if(s[1]=='A')
{
cout<<A<<" "<<B<<" ";
}
else
{
cout<<B<<" "<<A<<" ";
}
}
}
by Dyc_20140402 @ 2024-10-08 18:32:10
sb
by Dyc_20140402 @ 2024-10-08 18:32:18
sb
by Dyc_20140402 @ 2024-10-08 18:32:29
sb
by wangcm @ 2024-10-08 18:38:30
@QWlanren 最大的问题:char s[3];
改成string s就没问题了
by wangcm @ 2024-10-08 18:39:35
@QWlanren
修饰+改正过后的代码:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int swap;
int a,b,c;
cin>>a>>b>>c;
if(a>b){
swap=a;
a=b;
b=swap;
}
if(b>c){
swap=b;
b=c;
c=swap;
}
if(a>b)
{
swap=b;
b=a;
a=swap;
}
string s;
cin>>s;
if(s[0]=='A'){
cout<<a<<" ";
if(s[1]=='B'){
cout<<b<<" "<<c<<" ";
}
else{
cout<<c<<" "<<b<<" ";
}
}
else if(s[0]=='B')
{
cout<<b<<" ";
if(s[1]=='A'){
cout<<a<<" "<<c<<" ";
}
else{
cout<<c<<" "<<a<<" ";
}
}
else
{
cout<<c<<" ";
if(s[1]=='A'){
cout<<a<<" "<<b<<" ";
}
else{
cout<<b<<" "<<a<<" ";
}
}
return 0;
}
by 1357911BCC @ 2024-10-11 21:39:21
#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);
for (int i = 0; i < s.length(); i++) {
cout << a[s[i] - 'A'] << " ";
}
return 0;
}
试试这个 代码太长我头昏