Question address: Code
Question:
In the Lexicographic Order, the sequence is given starting from the lowercase letter.
A-1
B-2
...
Z-26
AB-27
...
Az-51
BC-52
...
Vwxyz-83681
...
The input string consists of lowercase letters A-Z in ascending order, which is based on the number of serial numbers output in the dictionary.
Solution:
Arrange and combine, remember the formula:
First, the length of a character is 26 to C (). When two characters are used, 25 are calculated from the beginning of a, and 24 are started with B... it can be calculated that when C () is three characters in turn, C )....
Therefore, the given string first calculates the sum of strings smaller than its length and then the number of strings equal to its length, when calculating equal values, always calculate the sum of the first character to ensure correctness. The sum of the calculated values is + 1. is the serial number of the string.
(Transfer) http://hi.baidu.com/you289065406/blog/item/d0900ff85e4b0b71024f563a.html#0
Code:
1 # include <algorithm> 2 # include <iostream> 3 # include <sstream> 4 # include <cstdlib> 5 # include <cstring> 6 # include <cstdio> 7 # include <string> 8 # include <bitset> 9 # include <vector> 10 # include <queue> 11 # include <stack> 12 # include <cmath> 13 # include <list> 14/ /# include <map> 15 # include <set> 16 using namespace STD; 17 /************************************** */18 # define ll long long19 # define in T64 _ int6420 # define PI 3.141592721 /******************************* * ******/22 const int INF = 0x7f7f7f7f; 23 const double EPS = 1e-8; 24 const double PIE = ACOs (-1.0); 25 const int d1x [] = {0,-, 1 }; 26 const int d1y [] = {-,}; 27 const int d2x [] = {0,-, 1}; 28 const int d2y [] =, -}; 29 const int FX [] = {-1,-1,-,}; 30 const int FY [] = {-, 1, -,-, 1}; 31 const int dirx [] = {-,-2, 2,-,-}; 32 const int diry [] = {-2,-2,-1,-, 2 }; 33/* vector <int> map [N]; Map [A]. push_back (B); int Len = map [v]. size (); */34 /************************************ ***/35 void openfile () 36 {37 freopen ("data. in "," rb ", stdin); 38 freopen (" data. out "," WB ", stdout); 39} 40 priority_queue <int> qi1; 41 priority_queue <int, vector <int>, greater <int> qi2; 42/*********************** Lili split line, the above is the template section **************** */43 int C [30] [30]; 44 int zuhe () 45 {46 int I, j; 47 for (I = 0; I <30; I ++) 48 {49 C [I] [0] = 1; 50 C [I] [I] = 1; 51 for (j = 1; j <I; j ++) 52 {53 c [I] [J] = C [I-1] [J-1] + C [I-1] [J]; 54} 55} 56} 57 int main () 58 {59 char s [15]; 60 zuhe (); 61 while (scanf ("% s", S )! = EOF) 62 {63 int sum = 0; 64 int Len = strlen (s); 65 int I; 66 int Ce = 0; 67 for (I = 0; I <len-1; I ++) 68 if (s [I + 1] <s [I]) 69 Ce = 1; 70 If (CE) 71 {72 printf ("0 \ n"); 73 continue; 74} 75 for (I = 1; I <Len; I ++) 76 sum + = C [26] [I]; 77 char C; 78 for (I = 0; I <Len; I ++) 79 {80 if (I) 81 C = s [I-1] + 1; 82 else83 c = 'a'; 84 while (C <s [I]) 85 {86 sum + = C ['Z'-C] [len-1-i]; 87 C ++; 88} 89} 90 printf ("% d \ n ", + + sum); 91 memset (S, 0, sizeof (s); 92} 93 return 0; 94}View code
Poj1850 (CODE)