C++ 4.8.2 和VS2013 在vector的定义上还有区别
vector<pair<string,int> > NUM; 在C++ 4.8.2 下必须加这个>>之间的空格 否则CE
在VS2013下没问题
先贴题如下:
The Mad Numerologist |
Numerology is a science that is used by many people to find out a mans personality, sole purpose of life, desires to experience etc. Some calculations of numerology are very complex, while others are quite simple. You can sit alone at home and do these easy calculations without taking any ones help. However in this problem you wont be asked to find the value of your name.
To find the value of a name modern numerologists have assigned values to all the letters of English Alphabet. The table on the left shows the numerical values of all letters of English alphabets. Five letters A, E, I, O, U are vowels. Rests of the letters are consonant. In this table all letters in column 1 have value 1, all letters in column 2 have value 2 and so on. So T has value 2, F has value 6, R has value 9, O has value 6 etc. When calculating the value of a particular name the consonants and vowels are calculated separately. The following picture explains this method using the name ``CHRISTOPHER RORY PAGE".
So you can see that to find the consonant value, the values of individual consonants are added and to find the vowel value the values of individual vowels are added. A mad Numerologist suggests people many strange lucky names. He follows the rules stated below while giving lucky names.
First line of the input file contains an integer N ( 0 < N250)
that indicates how many sets of inputs are there. Each of the next N
lines contains a single set of input. The description of each set is given
below: Each line contains an integer n ( 0 < n < 211) that indicates the
predefined length of the name.
For each set of input produce one line of output. This line contains the serial of output followed by the name that the numerologist would suggest following the rules above. All letters in the output should be uppercase English letters.
3 1 5 5
Case 1: A Case 2: AJAJA Case 3: AJAJA
代码没有AC 先不贴
。。。我遇到个奇葩的情况调了半天,,结果 是由于我把 Vowel最多次数 21 看成了20 才遇到的 T_T 看题不仔细 耽误好多时间
这种虐心的提交记录还是要粘上
总结
在VS2013下能过的代码并不代表不会CE 要在C:B下测试后确认能运行
看题要仔细啊
STL用的要适当 不能滥用 不明所以就用
AC代码如下 本想通过打表赚个0.00s可惜没如我所愿
1 #include<iostream> 2 #include<cstdio> 3 #include<string> 4 #include<cstdlib> 5 #include<algorithm> 6 #include<vector> 7 using namespace std; 8 #define MAX 220 //用打表法做 9 void init(); 10 11 string Vlst="AUEOI"; //有序V 。 C 表 12 string Clst = "JSBKTCLDMVNWFXGPYHQZR"; 13 14 vector<pair<string,int> > NUM; 15 int main(void) 16 { 17 //freopen("10785.out", "w", stdout); 18 init(); 19 int cnt; 20 scanf("%d",&cnt); 21 for (int i = 0; i < cnt; i++) 22 { 23 int in; 24 scanf("%d", &in); 25 printf("Case %d: ", i + 1); 26 printf("%s",NUM[in - 1].first); 27 printf("\n"); 28 } 29 } 30 31 void init() 32 { 33 for (int i = 1; i <=210;i++) 34 { 35 string tmp; 36 int curposv=0, curposc=0; //充当指针 37 int cntV, cntC; //充当计数器 38 cntV = cntC = 0; 39 int val = 0; 40 while (tmp.size() != i) 41 { 42 tmp += Vlst[curposv]; 43 val += (Vlst[curposv] - ‘A‘) % 8 + 1; 44 cntV++; 45 if (tmp.size() == i) break; 46 tmp += Clst[curposc]; 47 val += (Clst[curposc] - ‘A‘) % 8 + 1; 48 cntC++; 49 if (tmp.size() == i) break; 50 if (cntV == 21) { cntV = 0; curposv++; } 51 if (cntC == 5){ cntC = 0; curposc++; } 52 } 53 //按照字典序排序 不过这题都是大写不用考虑大小写问题 54 for (int m = 0;m < tmp.size()-1; m += 2) 55 { 56 if (m<tmp.size()) 57 for (int n = m + 2; n < tmp.size();n+=2) 58 if (n<tmp.size() && tmp[n] < tmp[m]) 59 { 60 char t = tmp[m]; 61 tmp[m] = tmp[n]; 62 tmp[n] = t; 63 } 64 } 65 for (int m = 1; m < tmp.size(); m += 2) 66 { 67 if (m<tmp.size()) 68 for (int n = m + 2; n < tmp.size(); n += 2) 69 if (n<tmp.size() && tmp[n] < tmp[m]) 70 { 71 char t = tmp[m]; 72 tmp[m] = tmp[n]; 73 tmp[n] = t; 74 } 75 } 76 //其实这个pair根本没什么用,直接string就可以 刚刚开始读题没明白留下的残局。。。 STL 77 NUM.push_back(make_pair(tmp,val)); 78 } 79 return; 80 }
UVA 10785 The Mad Numerologist,布布扣,bubuko.com
UVA 10785 The Mad Numerologist
原文:http://www.cnblogs.com/VOID-133/p/3572488.html