10分求助
  • 板块P1765 手机
  • 楼主zyabc
  • 当前回复3
  • 已保存回复3
  • 发布时间2022/5/29 16:22
  • 上次更新2023/10/28 00:21:07
查看原帖
10分求助
725788
zyabc楼主2022/5/29 16:22

例题已过,但是只能得10分,帮忙看看是为什么

#include<bits/stdc++.h>
using namespace std;

string text;
//26个按键字母的次数和空格按键次数 
int num[27]={1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,4,1,2,3,1,2,3,4,1};
int main()
{   int count=0;
	int lastIndex=-1;
	int thisIndex=-1;

	getline(cin,text);
	for(int i=0;i<text.size();i++)
	{
		if(text[i]==' ') thisIndex=26;
		if(text[i]>='a'&&text[i]<='z') 
		{thisIndex=text[i]-'a';
			count+=num[thisIndex];
		}
        if(text[i]=='\r') break;
	
	}
	cout<<count;
    return 0;
}
2022/5/29 16:22
加载中...