本文共 1472 字,大约阅读时间需要 4 分钟。
这个题真是无聊,今天做完CF,就在整这个题。。。开始理解错了题意了,发现给了一个文件的字典,文件的读入读出,早忘的差不多了,读出只能把一个字典,读成一个字符串,写了好长时间,改了N处,终于过了。。。做CF被虐爆,做这个更是被虐爆了。。。
1 /* 2 ID: cuizhe 3 LANG: C++ 4 TASK: namenum 5 */ 6 #include 7 #include 8 #include 9 #include 10 #include 11 using namespace std;12 char txt[10000000];13 map mm;14 long long o[13];15 int main()16 {17 int len,str,i,j,z;18 long long n,sum;19 FILE *fp;20 char *q = txt;21 freopen("namenum.in","r",stdin);22 fp = fopen("dict.txt","r");23 scanf("%lld",&n);24 freopen("namenum.out","w",stdout);25 fread(q,sizeof(txt),1,fp);26 len = strlen(txt);27 mm['A'] = 2;28 mm['B'] = 2;29 mm['C'] = 2;30 mm['D'] = 3;31 mm['E'] = 3;32 mm['F'] = 3;33 mm['G'] = 4;34 mm['H'] = 4;35 mm['I'] = 4;36 mm['J'] = 5;37 mm['K'] = 5;38 mm['L'] = 5;39 mm['M'] = 6;40 mm['N'] = 6;41 mm['O'] = 6;42 mm['P'] = 7;43 mm['R'] = 7;44 mm['S'] = 7;45 mm['T'] = 8;46 mm['U'] = 8;47 mm['V'] = 8;48 mm['W'] = 9;49 mm['X'] = 9;50 mm['Y'] = 9;51 str = 0;52 z = 1;53 o[1] = 1;54 for(i = 2; i <= 12; i ++)55 o[i] = o[i-1]*10;56 for(i = 0; i <= len; i ++)57 {58 if(txt[i] == '\n')59 {60 sum = 0;61 for(j = str; j <= i-1; j ++)62 {63 sum += mm[txt[j]]*o[i-j];64 }65 if(sum == n)66 {67 for(j = str; j <= i-1; j ++)68 printf("%c",txt[j]);69 printf("\n");70 z = 0;71 }72 str = i+1;73 }74 }75 if(z)76 printf("NONE\n");77 return 0;78 }
转载于:https://www.cnblogs.com/naix-x/archive/2012/10/21/2733054.html