#include "stdio.h"
#include "string.h"
#include "string"
#include "iostream"
#include "math.h"
#include "map"
#include "queue"
#include "malloc.h"
using namespace std;
map<char,string> mp; int main()
{
mp['']="";mp['']="";mp['']="";mp['']="";mp['']="";
mp['']="";mp['']="";mp['']="";mp['']="";mp['']="";
mp['A']="";mp['B']="";mp['C']="";mp['D']="";mp['E']="";
mp['F']="";
int a;
char test[];
cin >> a;
while(a--)
{ memset(test,,sizeof(test));
string b="";
cin>>test;
for(int i = ;i < strlen(test);i++)
{
b += mp[test[i]];
}
int len = b.length();
if(len%==)
b = "" + b;
else if(len%==)
b = "" + b;
int flag = ;
for(int i = ;i < b.length(); i = i + )
{
int num = *(b[i]-'')+*(b[i+]-'')+(b[i+]-'');
if(num)
flag = ;
if(flag)
cout<<num; }
cout<<endl;
}
return ;
}

但是这个跑在蓝桥杯的题目中会超时,因为map查询是对数时间复杂度放在循环中会超时

更改map后通过

#include "stdio.h"
#include "string.h"
#include "string"
#include "iostream"
#include "math.h"
#include "map"
#include "queue"
using namespace std;
map<char,string> mp; int main()
{
int a;
string test;
cin >> a;
while(a--)
{
string b="";
cin>>test;
for(int i=;i<test.length();i++)//遍历,字符串上加上每一位
{
switch(test[i])
{
case '':b+="";break;
case '':b+="";break;
case '':b+="";break;
case '':b+="";break;
case '':b+="";break;
case '':b+="";break;
case '':b+="";break;
case '':b+="";break;
case '':b+="";break;
case '':b+="";break;
case 'A':b+="";break;
case 'B':b+="";break;
case 'C':b+="";break;
case 'D':b+="";break;
case 'E':b+="";break;
case 'F':b+="";break;
default:break;
}
}
int len = b.length();
if(len%==)
b = "" + b;
else if(len%==)
b = "" + b;
int flag = ;
for(int i = ;i < b.length(); i = i + )
{
int num = *(b[i]-'')+*(b[i+]-'')+(b[i+]-'');
if(num)
flag = ;
if(flag)
cout<<num;
}
cout<<endl;
} return ;
}

最新文章

  1. 记录下帮助一位网友解决的关于android子控件的onTouch或onClick和父OnTouch 冲突的问题。
  2. 第二节:模型(Models)和管理后台(Admin site)
  3. TJI读书笔记16-异常处理
  4. 【代码笔记】iOS-给背景图加上移动的手势
  5. GitHub注册流程(中英对比)
  6. 生理周期[PKU1006]
  7. zabbix监控tomcat
  8. 吃豆子(Packman)
  9. AndroidStudio用微信官方方法接入微信分享功能
  10. php 调试工具及学习PHP垃圾回收机制了解引用计数器的概念
  11. eclipse 工程加入ant以支持自动打war包
  12. C#系列之String和StringBuilder
  13. WinForm TextBox自定义扩展方法数据验证
  14. mysql 表格中的数据量过大,修改数据库字段信息会花费很长的时间
  15. WebIM(2)---消息缓存
  16. IE11中的F12无效的问题
  17. (转ORCLE导入导出命令)
  18. Bootstrap-datepicker3官方文档中文翻译---概述(原版翻译 http://bootstrap-datepicker.readthedocs.io/en/latest/index.html)
  19. PERL学习笔记---正则表达式
  20. Elasticsearch实践(三):Mapping

热门文章

  1. JN_0001:在微信朋友圈分享时长大于10s的视频
  2. 第八节:常见安全隐患和传统的基于Session和Token的安全校验
  3. windows下 cmd 界面的替代者 cmder 推荐!
  4. updateXML 注入 python 脚本
  5. luogu P5294 [HNOI2019]序列
  6. Kaldi nnet3的fastlstm与标准LSTM
  7. 转载-CentOS7关闭防火墙
  8. ve2.0 v-for循环报错的解决方案
  9. python3 使用pip安装(命令行中)失败或 “not a supported wheel” 解决方案!
  10. C# - Visual Studio简明操作