我的pku1002有什么问题呢?难道有什么陷阱

来源:百度知道 编辑:UC知道 时间:2024/06/29 21:38:13
#include <iostream>
#include <string>
#include <algorithm>
#include <stdio.h>

using namespace std;

inline void table(char& ch)
{
switch(ch)
{
case 'A':
case 'B':
case 'C': ch = '2'; break;
case 'D':
case 'E':
case 'F': ch = '3'; break;
case 'G':
case 'H':
case 'I': ch = '4'; break;
case 'J':
case 'K':
case 'L': ch = '5'; break;
case 'M':
case 'N':
case 'O': ch = '6'; break;
case 'P':
case 'R':
case 'S': ch = '7'; break;
case 'T':
case 'U':
case 'V': ch = '8'; break;
case 'W':
case 'X':
case 'Y': c

你的基本正确,但是没注意边界,有一处边界改了就好了.AC了的:
#include <iostream>
#include <string>
#include <algorithm>
#include <stdio.h>

using namespace std;

inline void table(char& ch)
{
switch(ch)
{
case 'A':
case 'B':
case 'C': ch = '2'; break;
case 'D':
case 'E':
case 'F': ch = '3'; break;
case 'G':
case 'H':
case 'I': ch = '4'; break;
case 'J':
case 'K':
case 'L': ch = '5'; break;
case 'M':
case 'N':
case 'O': ch = '6'; break;
case 'P':
case 'R':
case 'S': ch = '7'; break;
case 'T':
case 'U':
case 'V': ch = '8'; break;
case 'W':
case 'X':