USER: tianbing tianbing [tbbd4261]
TASK: namenum
LANG: C++
Compiling...
Compile: OK
Executing...
Test 1: TEST OK [0.011 secs, 2932 KB]
Test 2: TEST OK [0.011 secs, 2932 KB]
Test 3: TEST OK [0.000 secs, 2932 KB]
Test 4: TEST OK [0.011 secs, 2932 KB]
Test 5: TEST OK [0.000 secs, 2932 KB]
Test 6: TEST OK [0.000 secs, 2932 KB]
Test 7: TEST OK [0.011 secs, 2932 KB]
Test 8: TEST OK [0.000 secs, 2932 KB]
Test 9: TEST OK [0.000 secs, 2932 KB]
Test 10: TEST OK [0.011 secs, 2932 KB]
Test 11: TEST OK [0.000 secs, 2932 KB]
Test 12: TEST OK [0.011 secs, 2932 KB]
Test 13: TEST OK [0.011 secs, 2932 KB]
Test 14: TEST OK [0.011 secs, 2932 KB]
Test 15: TEST OK [0.022 secs, 2932 KB]
All tests OK.
Your program ('namenum') produced all correct answers! This is your
submission #2 for this problem. Congratulations!
Here are the test data inputs:
------- test 1 -------
4734
------- test 2 -------
234643
------- test 3 -------
5747867437
------- test 4 -------
223
------- test 5 -------
532
------- test 6 -------
546
------- test 7 -------
53662
------- test 8 -------
5455426
------- test 9 -------
26678268463
------- test 10 -------
463373633623
------- test 11 -------
282742662
------- test 12 -------
463373633623
------- test 13 -------
2336
------- test 14 -------
5264
------- test 15 -------
426
Keep up the good work!
Thanks for your submission!
代码:
由于一个数组对应三个字母,较麻烦,所以用字母对应数字较好,而且与已排序的dict.txt中的名字对应后的数字串也是排好序的
WA了一次,原因是没有把ofstream对象cout,传给solve 函数,输出到标准输出了;
1
/**//*
2ID:tbbd4261
3LANG:C++
4PROG:namenum
5*/
6//#include<iostream>
7#include<string>
8#include<vector>
9#include<fstream>
10using namespace std;
11int a[] = {2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,-1,7,7,8,8,8,9,9,9,-1};
12int main()
13{
14 void solve(vector<string> &vec,string &str,ofstream &cout);
15 ifstream cin("namenum.in");
16 ofstream cout("namenum.out");
17 ifstream tin("dict.txt");
18 string str,temp=""; int i,n,j;
19 cin>>str;
20 vector<string>vec;
21 while(tin>>temp)
22 {
23 if(temp.size()==str.size())vec.push_back(temp);
24
25 }
26
27 solve(vec,str,cout);
28
29 //system("pause");
30 return 0;
31}
32
33void solve(vector<string> &vec,string &str,ofstream &cout)
34{
35 bool find=true,result=false;
36 int i,j,k,n;
37 for(i=0; i<vec.size(); i++)
38 {
39 n=vec[i].size(); find=true;
40 for(j=0;j<n; j++)
41 {
42 if(a[vec[i][j]-'A']+'0'!=str[j]){ find=false; break; }
43 }
44 if(find){ cout<<vec[i]<<endl; result=true;}
45 }
46
47 if(!result)cout<<"NONE"<<endl;
48}