手机键盘

 

                                                              手机键盘

                                                                   Time Limit: 1000 ms Memory Limit: 65536 KiB

Problem Description

大家应该都见过那种九键的手机键盘,键盘上各字母的分布如下图所示。

当我们用这种键盘输入字母的时候,对于有些字母,往往会需要按多次键才能输入。

比如:a, b, c 都在“2”键上,输入 a 只需要按一次,而输入 c 需要连续按三次。

连续输入多个字母的规则如下:

1、如果前后两个字母不在同一个按键上,则可在输入前一个字母之后直接输入下一个字母,如:ad 需要按两次键盘,kz 需要按 6 次。

2、如果前后两个字母在同一个按键上,则输入完前一个字母之后需要等待一段时间才能输入下一个字母,如 ac,在输入完 a 之后,需要等一会儿才能输入 c。

现在假设每按一次键盘需要花费一个时间段,等待时间需要花费两个时间段。

现在给出一串只包含小写英文字母的字符串,计算出输入它所需要花费的时间。

Input

 

输入包含多组测试数据,对于每组测试数据:

输入为一行只包含小写字母的字符串,字符串长度不超过100。

Output

 

对于每组测试数据,输出需要花费的时间。

Sample Input

bob
www

Sample Output

7
7

import java.util.*;
class Point
{
	String str;
	public Point(String str)
	{
		this.str = str;
	}
}

public class Main{
	public static void main(String [] args)
	{
		Scanner reader = new Scanner(System.in);
		Point [] Str = {
				new Point("abc"),
				new Point("def"),
				new Point("ghi"),
				new Point("jkl"),
				new Point("mno"),
				new Point("pqrs"),
				new Point("tuv"),
				new Point("wxyz"),
		};
		while(reader.hasNext())
		{
			int ans = 0;
			int k = 0;
			String str;
			str = reader.nextLine();
			for(int i = 0; i <= str.length() - 1; i++)
			{
				if(i == 0)
				{
					for(int j = 0; j <= 7; j++)
					{
						if(Str[j].str.indexOf(str.charAt(i)) != -1)
						{
							ans += Str[j].str.indexOf(str.charAt(i)) + 1;
							k = j;
							break;
						}
					}
				}
				else 
				{
					if(Str[k].str.indexOf(str.charAt(i)) != -1)
					{
						ans += 2;
						ans += Str[k].str.indexOf(str.charAt(i)) + 1;
					}
					else
					{
						for(int j = 0; j <= 7; j++)
						{
							if(Str[j].str.indexOf(str.charAt(i)) != -1)
							{
								ans += Str[j].str.indexOf(str.charAt(i)) + 1;
								k = j;
								break;
							}
						}
					}
				}
			}
			System.out.println(ans);
		}
		reader.close();
	}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值