讨论 / 為啥子這樣?
我为数学狂 2011-10-06 18:16:00
点我顶贴 收藏 删除
状态: Unaccepted

测评机: Xeond[6]

得分: 90分

提交日期: 2011-9-30 14:04:00

有效耗时: 453毫秒

测试结果1: 通过本测试点|有效耗时62ms

测试结果2: 通过本测试点|有效耗时47ms

测试结果3: 通过本测试点|有效耗时47ms

测试结果4: 通过本测试点|有效耗时47ms

测试结果5: 通过本测试点|有效耗时47ms

测试结果6: 通过本测试点|有效耗时46ms

测试结果7: 通过本测试点|有效耗时47ms

测试结果8: 通过本测试点|有效耗时63ms

测试结果9: 通过本测试点|有效耗时47ms

测试结果10: 测试结果错误.错误结果为:382

正确结果应为:384

提交代码: view sourceprint?01.#include<iostream>

02.#include<string.h>

03.using namespace std;

04.int main()

05.{

06.

char a[200];

07.

int s=0;

08.

cin.getline(a,200);

09.

int x=strlen(a);

10.

for(int i=0;i<x;i++)

11.

switch(int(a[i]))

12.

{

13.

case 32:case 97:case 100:case 103:case 106:case 109:case 112:case 116:case 119:s+=1;break;

14.

case 98:case 101:case 104:case 107:case 110:case 113:case 117:case 120:s+=2;break;

15.

case 99:case 102:case 105:case 108:case 111:case 114:case 118:case 121:s+=3;break;

16.

case 115:case 122:s+=4;

17.

default:;

18.

}

19.

cout<<s;

20.

return 0;

21.}

#1 a137567878@2011-10-06 18:16:00
回复 删除
cin.getline(a,200); 改成cin.getline(a,201);

因为字符串长度为200是。第200个字符是 '\0'。

少的2是最后一个字符出错

查看更多回复
提交回复