
原题链接
https://www.luogu.com.cn/problem/P1603
解题思路
这道题,我的思路有打表的成分,还用了哈希。
参考代码
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 
 | #include<iostream>#include<cstdio>
 #include<cmath>
 #include<cstring>
 #include<algorithm>
 using namespace std;
 string s;
 int a[1111],sx[1111],h[55],cnt,temp,start;
 int hash(string x)
 {
 int const b=1111111111;
 int ans=0;
 int lens=x.length();
 for(int i=0;i<lens;i++)
 {
 ans*=b;
 ans+=x[i];
 }
 return ans;
 }
 int main()
 {
 
 h[1]=hash("one");
 h[2]=hash("two");
 h[3]=hash("three");
 h[4]=hash("four");
 h[5]=hash("five");
 h[6]=hash("six");
 h[7]=hash("seven");
 h[8]=hash("eight");
 h[9]=hash("nine");
 h[10]=hash("ten");
 h[11]=hash("eleven");
 h[12]=hash("twelve");
 h[13]=hash("thirteen");
 h[14]=hash("fourteen");
 h[15]=hash("fifteen");
 h[16]=hash("sixteen");
 h[17]=hash("seventeen");
 h[18]=hash("eighteen");
 h[19]=hash("nineteen");
 h[20]=hash("twenty");
 h[21]=hash("a");
 h[22]=hash("both");
 h[23]=hash("first");
 h[24]=hash("second");
 h[25]=hash("third");
 h[26]=hash("another");
 for(int i=1;i<=6;i++)
 {
 cin>>s;
 if(s[0]<'a')s[0]+=32;
 temp=hash(s);
 if(temp==h[1]||temp==h[21]||temp==h[23]||temp==h[26])a[i]=1;
 if(temp==h[2]||temp==h[22]||temp==h[24])a[i]=4;
 if(temp==h[3]||temp==h[25])a[i]=9;
 if(temp==h[4])a[i]=16;
 if(temp==h[5]||temp==h[15])a[i]=25;
 if(temp==h[6])a[i]=36;
 if(temp==h[7])a[i]=49;
 if(temp==h[8])a[i]=64;
 if(temp==h[9])a[i]=81;
 if(temp==h[10]||temp==h[20])a[i]=0;
 if(temp==h[11])a[i]=21;
 if(temp==h[12])a[i]=44;
 if(temp==h[13])a[i]=69;
 if(temp==h[14])a[i]=96;
 if(temp==h[16])a[i]=56;
 if(temp==h[17])a[i]=89;
 if(temp==h[18])a[i]=24;
 if(temp==h[19])a[i]=61;
 }
 cin>>s;
 sort(a+1,a+7);
 for(int i=1;i<=6;i++)
 {
 sx[++cnt]=a[i]/10;
 sx[++cnt]=a[i]%10;
 }
 while(sx[start]==0&&start<cnt)start++;
 for(int i=start;i<=cnt;i++)cout<<sx[i];
 return 0;
 }
 
 |