码迷,mamicode.com
首页 > 移动开发 > 详细

题目1079:手机键盘(对应关系)

时间:2017-05-03 19:13:31      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:copyright   names   UI   get   std   mem   参考   mat   using   

题目链接:http://ac.jobdu.com/problem.php?pid=1079

详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus

参考代码:

//
//  1079 手机键盘.cpp
//  Jobdu
//
//  Created by PengFei_Zheng on 03/05/2017.
//  Copyright © 2017 PengFei_Zheng. All rights reserved.
//
 
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <cstring>
#include <cmath>
#include <climits>
#define MAX_SIZE 110
 
using namespace std;
 
char str[MAX_SIZE];
int pos[26]={2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9};
int kase[26]={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 main(){
    while(scanf("%s",str)!=EOF){
        int len = (int)strlen(str);
        int sum = kase[str[0]-a];
        for(int i = 1 ; i < len ; i++){
            if(pos[str[i]-a]!=pos[str[i-1]-a]){
                sum+=(kase[str[i]-a]);
            }
            else {
                sum+=2+kase[str[i]-a];
            }
        }
        printf("%d\n",sum);
    }
    return 0;
}
/**************************************************************
    Problem: 1079
    User: zpfbuaa
    Language: C++
    Result: Accepted
    Time:10 ms
    Memory:1520 kb
****************************************************************/

 

题目1079:手机键盘(对应关系)

标签:copyright   names   UI   get   std   mem   参考   mat   using   

原文地址:http://www.cnblogs.com/zpfbuaa/p/6803262.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!