首页 > 其他分享 >九宫格按键输入法(华为机试)

九宫格按键输入法(华为机试)

时间:2022-11-14 22:56:12浏览次数:41  
标签:输入法 temp int 九宫格 fast str 机试 include size

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
vector<string> re{ {" "},{",."},{"abc"},{"def"},{"ghi"},{"jkl"},{"mno"},{"pqrs"},{"tuv"},{"wxyz"} };
void op(string str) {
	bool flag = false;//代表数字模式
	int p = 0;
	while (p < str.size()) {
		string temp;
		//分离数字
		while (str[p] <= '9' && str[p] >= '0' && p < str.size()) {
			temp.push_back(str[p]);
			++p;
		}
		//不同模式的处理,flag为0代表默认模式,
		if (flag) {
			int slow = 0;
			int fast = 0;
			while (fast < temp.size()) {
				int cnt =0;
				int index = temp[slow] - '0';
				while (temp[fast] == temp[slow] && fast < temp.size()) {
					++cnt;
					++fast;
				}
				slow = fast;
				if (cnt < re[index].size())
				{
					cout << re[index][cnt - 1];
				}
				else {
					cout << re[index][0];
				}
			}	
		}		
		else {
			for (char ch : temp) {
				cout << ch - '0' ;
			}
		}
		if (str[p] == '#') {
			flag = flag ? false : true;
		}
			++p;
	}

}
//#222235/56
///56123#222235/56
int main() {
	string str;
	getline(cin, str);
	op(str);
}

标签:输入法,temp,int,九宫格,fast,str,机试,include,size
From: https://www.cnblogs.com/chunbai11/p/16890831.html

相关文章

  • 九宫格
    <?php/* 九宫格计算程序 by张阳潜龙勿用[email protected] 20111226*/echo"<spanstyle='font-size:12px'>这里是九宫格</span>";?><script>varinit_x ......
  • ubuntu安装搜狗输入法
    https://shurufa.sogou.com/linux?r=pinyin在如上链接下载,然后使用dpkg命令安装在电脑设置中找到“区域和语言”,然后点击“管理已安装的语言”,将系统输入法系统更改为“f......
  • linux_mint_21 vim配置:剪贴板支持和输入法自动切换
    一、vim的剪贴板支持有的vim版本不支持系统剪切板,也就是说在vim编辑器外面复制的内容,不能够粘贴到vim中;在vim中通过yy、d、c复制剪切的内容也不能粘贴在vim编辑器外......
  • 报文解压缩(华为机试)
    #include<iostream>#include<string>#include<stack>#include<algorithm>usingnamespacestd;stringop(intnum,string&str){ stringtemp; for(inti=0;i......
  • 贪吃蛇(华为机试)
    #include<deque>#include<iostream>#include<vector>#include<algorithm>#include<string>//每次蛇移动只会有3种情况:////1.撞墙(坐标越界)直接返回长度;//2.空格......
  • 一道zhangying机试题
    功能很好实现,但是用到的设计模式没有搞清楚,有一句话没太懂:每个调节项目调节时触发的动作会修改,不知道是什么含义,有明白的童鞋指导一下,选用何种设计模式。下面看一下功能代码......
  • vue.js3:分割图片为四宫格九宫格等形式([email protected])
    一,js代码:<template><div><divstyle="width:800px;margin:auto;display:flex;flex-direction:column;"><div>请选择上传图片:<inputtype="file"id......
  • win10系统下鼠标点击任务栏,导致托盘输入法图标(qq拼音、搜狗拼音)闪动的解决方案
    之前找了很多解决方案,可能是场景不一样,一直没解决。后来偶然间发现一种很简单的处理方式。有类似情况的可以试试。问题场景还原   如上图可见,鼠标切换到任......
  • 快来测试下你的输入法正不正经 - 一个@引发的血案正在上映~
    事情是这样式儿滴~~~~在IM工具、Wiki文档中我们经常使用​​@​​​符号来做提及人、提及文档的功能,最近胡哥就是在做这个业务需求的时候被​​@​​这个符号坑惨了。PM想要......
  • keepass关闭输入法自动执行自动输入
    背景:自动输入账号需要切换到英文状态,否则会噼里啪啦输入一堆中文内容使用IIME.plgx插件可自动关闭输入法,再输入字段可解决这个问题插件地址:https://github.com/iuuniang/......