萌新问问题

P3864 [USACO1.2] 命名那个数字 Name That Number

# 回复 很有可能是cin的锅 因为某谷使用的是虚拟机,\r和\n都是回车,所以cin可能会出问题 其实我也只有51分(不过神奇的是,我的程序正好51行) ``` #include<bits/stdc++.h> using namespace std; bool ac_ak=true; string st; map<char,int> f; int num[20]; int nl; bool ans; void pre() { f['Q']=f['Z']=0; f['A']=f['B']=f['C']=2; f['D']=f['E']=f['F']=3; f['G']=f['H']=f['I']=4; f['J']=f['K']=f['L']=5; f['M']=f['N']=f['O']=6; f['P']=f['R']=f['S']=7; f['T']=f['U']=f['V']=8; f['W']=f['X']=f['Y']=9; } int main() { // freopen("1.in","r",stdin); // freopen("1.out","w",stdout); pre(); cin>>st; nl=st.size(); for(int i=0;i<nl;i++) num[i]=st[i]-'0'; for(int i=1;i<=4617;i++) { cin>>st; if(st.size()==nl) { bool fl=true; for(int j=0;j<nl;j++) if(f[st[j]]!=num[j]) { fl=false; break; } if(fl==true) { cout<<st; ans=true; } } } if(ans==false) printf("NONE\n"); return 0; } ```
by fyz2006 @ 2020-02-21 00:00:45


@[fyz2006](/user/106590) 我用cin也对了
by songyuan888 @ 2020-02-28 11:34:11


@[songyuan888](/user/182229) 怎么做的
by fyz2006 @ 2020-02-28 22:21:04


```cpp #include<iostream> #include<algorithm> #include<string> using namespace std; int main() { int i,w; string s,n; bool m,b,t; cin>>n; t=0; while(cin>>s) { m=0; b=0; if(s.size()!=n.size()) m=1; if(m==0) { for(i=0;i<s.size();i++) { w=0; if(s[i]=='A'||s[i]=='B'||s[i]=='C') w=2; if(s[i]=='D'||s[i]=='E'||s[i]=='F') w=3; if(s[i]=='G'||s[i]=='H'||s[i]=='I') w=4; if(s[i]=='J'||s[i]=='K'||s[i]=='L') w=5; if(s[i]=='M'||s[i]=='N'||s[i]=='O') w=6; if(s[i]=='P'||s[i]=='R'||s[i]=='S') w=7; if(s[i]=='T'||s[i]=='U'||s[i]=='V') w=8; if(s[i]=='W'||s[i]=='X'||s[i]=='Y') w=9; if(w!=(int)(n[i]-'0')) { b=1; break; } } if(b==0) { t=1; cout<<s<<endl; } } } if(t==0) cout<<"NONE"<<endl; return 0; } ```
by songyuan888 @ 2020-02-29 09:01:45


@[songyuan888](/user/182229) 感觉也差不多呀(USACO的题目真坑)
by fyz2006 @ 2020-02-29 23:34:15


@[fyz2006](/user/106590) 大佬,你半夜11点多还上洛谷?(据帖子回复时间证明)
by songyuan888 @ 2020-03-01 07:52:49


@[songyuan888](/user/182229) 大佬,你早上7点多还上洛谷?我还在吃早饭呢(据帖子回复时间证明)
by fyz2006 @ 2020-03-01 21:12:55


@[fyz2006](/user/106590) 求帮看一下我的代码 ```cpp #include<bits/stdc++.h> using namespace std; #define MAXN 5000 const int all=4617; map<char,char> ctoc; void setup_ctoc_map(){ ctoc['A']='2'; ctoc['B']='2'; ctoc['C']='2'; ctoc['D']='3'; ctoc['E']='3'; ctoc['F']='3'; ctoc['G']='4'; ctoc['H']='4'; ctoc['I']='4'; ctoc['J']='5'; ctoc['K']='5'; ctoc['L']='5'; ctoc['M']='6'; ctoc['N']='6'; ctoc['O']='6'; ctoc['P']='7'; ctoc['R']='7'; ctoc['S']='7'; ctoc['T']='8'; ctoc['U']='8'; ctoc['V']='8'; ctoc['W']='9'; ctoc['X']='9'; ctoc['Y']='9'; ctoc['Q']='0'; ctoc['Z']='0'; return; } int main(){ setup_ctoc_map(); string give,now; bool ok; cin>>give; for(int i=1;i<=all;i++){ cin>>now; if(now.length()==give.length()){ ok=true; for(int i=0;i<give.length();i++){ if(ctoc[now[i]]!=give[i]){ ok=false; break; } } if(ok){ cout<<now<<endl; } } } return 0; } ```
by RDFZchenyy @ 2022-03-01 22:58:08


@[RDFZchenyy](/user/567610) 没有考虑输出"NONE"的情况。如果没有有效名字则输出"NONE"
by _Yvette_ @ 2022-12-18 16:19:33


|