每次遇到这种字符串题总是奇奇怪怪的会WA掉……
用sort排序然后map映射一下,本地绝对AC但交上去就WA了……
#include<bits/stdc++.h>
using namespace std;
inline int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
return x*f;
}
int a[3];
char s[3];
map<char,int> h;
int main(){
a[0]=read(),a[1]=read(),a[2]=read();
sort(a,a+3);
h['A']=a[0],h['B']=a[1],h['C']=a[2];
gets(s);
for(int i=0;i<3;i++)printf("%d ",h[s[i]]);
return 0;
}
另外,关于字符串读入:
- 为什么用
scanf("%c",&...)
,cin>>...
和getchar
会不一样的结果(AC,WA,RE,不分先后)?
- 同上,字符串输入也是用
scanf("%s",&...)
,cin>>...
和gets(...)
不同的结果。
- 用
char[105]
和string
也会有玄学区别。
是不是有是否读入空格或回车的区别?
上次月赛的2B,一开始用cin,后来想卡常用scanf和gets和getchar都错了(有RE有WA有AC),就cin没错,什么原因?