只有70分,没过的样例RE了,没找到问题啊
查看原帖
只有70分,没过的样例RE了,没找到问题啊
1140371
ruanertanjing楼主2024/7/27 15:31
// P1765 手机
// https://www.luogu.com.cn/problem/P1765

#include <iostream>
#include <cstring>
#include <string>
#include <functional>
#include <climits>

#define quickio ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define endl "\n"

using namespace std;
typedef long long ll;

string board[8] = { "abc", "def", "ghi", "jkl", "mno", "pqrs","tuv", "wxyz"};

void solve()
{
	string s;
	getline(cin, s);
	int sz = s.size();
	int ans = 0;

	for (int i = 0; i < sz; i++)
	{
		if (s[i] == ' ')
			ans++;
		else if (s[i] == 's' || s[i] == 'z')
		{
			ans += 4;
		}
		else
		{
			int x = (s[i] - 'a') / 3;
			int j = 0;
			ans++;
			while (board[x][j] != s[i])
			{
				ans++;
				j++;

				if (j == 3)
				{
					j = 0;
					if (x == 7)
						x--;
					else
						x++;
					
					ans -= 3;
				}
			}
		}
	}
	cout << ans << endl;
}

int main()
{
	solve();
	return 0;
}
2024/7/27 15:31
加载中...