|
发表于 2020-8-11 17:29:32
|
显示全部楼层
162
Process returned 0 (0x0) execution time : 0.054 s
Press any key to continue.
又可以利用Excel VBA处理源文件使之易于输入
- Public Sub PE42()
- Open "C:\Users\zcfcf\Desktop\words.txt" For Input As #1
- Dim s As String
- Dim cnt As Integer
- cnt = 1
- Do Until EOF(1)
- Input #1, s
- Range("a" & CStr(cnt)).Value = s
- cnt = cnt + 1
- Loop
- Close #1
- End Sub
复制代码
接着利用ASCII码天然的编码特性计算单词的值,并加以统计
- #include<iostream>
- #include<cstdio>
- #include<string>
- using namespace std;
- const int a[] = {1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120, 136,
- 153, 171, 190, 210, 231, 253, 276, 300, 325, 351};
- int calc(const string & s){
- int res = 0;
- for (int i = 0;i < s.length();i++)
- res += s[i] - 'A' + 1;
- return res;
- }
- int main(){
- freopen("i.in","r",stdin);
- string s;
- int cnt = 0;
- while(cin >> s){
- int t = calc(s);
- for (int i = 0;a[i] <= 351;i++)
- if (t == a[i]) { cnt++; break; }
- }
- cout << cnt << endl;
- return 0;
- }
复制代码 |
|