[USACO] [enumeration] Preface Numbering

Meaning of the questions:

Enter a number N, the output [1, N] is the number after the digital conversion of each letter appears in Roman numerals.

Ideas:

Violence had ... wrote a program converting Arabic numerals Roman numerals, then enumerate the digital string to find the letters.

Encountered no brief pit is the Roman numeral representation 450! !

Roman numerals and Arabic numerals each prospective change the subject leetcode above, may be affected by this it ......

Analysis of the solution to a problem which has to learn from these places:
* strcat the two char [] connect

The remaining problem is not the solution in detail to understand> <

 1 /*
 2 ID :ggy_7781
 3 TASK :prefix
 4 LANG :C++11
 5 */
 6 
 7 #include <bits/stdc++.h>
 8 using namespace std;
 9 
10 char a[200003];
11 char strs[203][13];
12 char tmp[79];
13 bool cmp(pair<int,int> l,pair<int,int>r)
14 {
15     if(l.first != r.first)
16         return l.first < r.first;
17     return l.second < r.second;
18 }
19 int main(){
20     freopen("prefix.in","r",stdin);
21     freopen("prefix.out","w",stdout);
22     int tot =0;
23     while(cin>>strs[tot])
24     {
25         if(strs[tot][0] == '.')
26             break;
27         tot ++;
28     }
29     while(cin>>tmp)
30         strcat(a,tmp);
31     int len = strlen(a);
32     vector<pair<int,int> > ans;
33     for(int i = 0;i < tot;i ++)
34     {
35         int leni = strlen(strs[i]);
36         for(int j = 0;j < len;j ++)
37         {
38             if(a[j] == strs[i][0])
39             {
40                 int op = j;
41                 bool ok = true;
42                 int k;
43                 for(k = 0;k < leni && j <len;k ++,j++)
44                 {
45                     if(strs[i][k]!=a[j])
46                     {
47                         ok = false;
48                         break;
49                     }
50                 }
51                 if(ok && k==leni)
52                 {
53                     ans.push_back(pair<int,int>(op,j) );
54                 }
55                 j = op;
56             }
57         }
58     }
59     sort(ans.begin(),ans.end(),cmp);
60     if(ans[0].first != 0)
61     {
62         cout<<0<<endl;
63         return 0;
64     }
65     int nowpos = ans[0].second;
66     int j = 0;
67     while(j < ans.size() && ans[j].first <= nowpos && nowpos <= ans[j].second)
68     {
69         nowpos = ans[j].second;
70         j ++;
71     }
72     cout<<nowpos<<endl;
73     return 0;
74 }

Guess you like

Origin www.cnblogs.com/ggy778/p/12231448.html