洛谷 P1765 手机 题解(字符串 C/C++)

//#define LOCAL
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cctype>
#define inf 0x3f3f3f3f
#define eps 1e-6
using namespace std;
#define clr(x) memset(x,0,sizeof((x)))
const int maxn = 1e4+1;//2e6+1
#define MAX(a,b,c) ((a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c)))
#define _max(a,b) ((a) > (b) ? (a) : (b))
#define _min(a,b) ((a) < (b) ? (a) : (b))
#define _for(a,b,c) for(int a = b;a<c;a++)
int readchar() {
    
    
	int ch;
	for(;;) {
    
    
		ch = getchar();
		if(ch!='\n'&&ch!='\r')return ch;
	}
}
int main()
{
    
    
#ifdef LOCAL 
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);
#endif
	int alpa[] = {
    
    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};
	int ch,ans = 0;
	//用getline读也行
	while((ch=readchar())!=EOF) {
    
    
		if(ch==' ') ans++;
		else ans+=alpa[ch-'a'];
	}
	cout<<ans;
	
    return 0;
}

猜你喜欢

转载自blog.csdn.net/Jason__Jie/article/details/112685767