当前位置: 首页 > 编程日记 > 正文

字符串专题:map POJ 1002

第一次用到是在‘校内赛总结’扫地那道题里面,大同小异

map<string,int>str 可以专用做做字符串的匹配之类的处理

string donser;

str [donser]++ 自动存donser到map并且值加一,如果发现重复元素不新建直接加一,

map第一个参数是key,默认字典序升序排列key

map<string,int>::iterator ii;         map的迭代器
for(ii=outputer.begin();ii!=outputer.end();++ii)  迭代器遍历
{
  if(ii->second>1)                     map第一个参数 ii->first或者 (*ii).first ;第二个参数 ii->second或者 (*ii).second
  {
    donser=ii->first;
    cout<<donser<<" "<<ii->second<<endl;
  }
}

POJ 1002 http://poj.org/problem?id=1002

对电话号码做化数字处理,然后匹配

#include<iostream>
#include<cstdio>
#include<string>
#include<map>
using namespace std;
string astr;
void deal()
{int len=astr.size();for(int i=0;i<len;i++){if(astr[i]=='-'){astr.erase(i,1);i--;continue;}if(astr[i]=='A'||astr[i]=='B'||astr[i]=='C'){astr.replace(i,1,"2");}if(astr[i]=='D'||astr[i]=='E'||astr[i]=='F'){astr.replace(i,1,"3");}if(astr[i]=='G'||astr[i]=='H'||astr[i]=='I'){astr.replace(i,1,"4");}if(astr[i]=='J'||astr[i]=='K'||astr[i]=='L'){astr.replace(i,1,"5");}if(astr[i]=='M'||astr[i]=='N'||astr[i]=='O'){astr.replace(i,1,"6");}if(astr[i]=='P'||astr[i]=='R'||astr[i]=='S'){astr.replace(i,1,"7");}if(astr[i]=='T'||astr[i]=='U'||astr[i]=='V'){astr.replace(i,1,"8");}if(astr[i]=='W'||astr[i]=='X'||astr[i]=='Y'){astr.replace(i,1,"9");}}return;
}
int main()
{int T,lable=0;map<string,int>outputer;scanf("%d",&T);int i=0,j=T;while(j--){cin>>astr;deal();outputer[astr]++;}map<string,int>::iterator ii;for(ii=outputer.begin();ii!=outputer.end();++ii){if(ii->second>1){astr=ii->first;astr.insert(3,"-");cout<<astr<<" "<<ii->second<<endl;lable=1;}}if(!lable) cout<<"No duplicates.";return 0;
}

转载于:https://www.cnblogs.com/dzzy/p/5470841.html

相关文章:

【洛谷P1508】吃吃吃

题目背景 问世间&#xff0c;青春期为何物&#xff1f; 答曰&#xff1a;“甲亢&#xff0c;甲亢&#xff0c;再甲亢&#xff1b;挨饿&#xff0c;挨饿&#xff0c;再挨饿&#xff01;” 题目描述 正处在某一特定时期之中的李大水牛由于消化系统比较发达&#xff0c;最近一直处…

前端和后端开发人员比例_前端开发人员vs后端开发人员–实践中的定义和含义

前端和后端开发人员比例Websites and applications are complex! Buttons and images are just the tip of the iceberg. With this kind of complexity, you need people to manage it, but which parts are the front end developers and back end developers responsible fo…

Linux 创建子进程执行任务

Linux 操作系统紧紧依赖进程创建来满足用户的需求。例如&#xff0c;只要用户输入一条命令&#xff0c;shell 进程就创建一个新进程&#xff0c;新进程运行 shell 的另一个拷贝并执行用户输入的命令。Linux 系统中通过 fork/vfork 系统调用来创建新进程。本文将介绍如何使用 fo…

metasploit-smb扫描获取系统信息

1.msfconsle 2.use auxiliary/scanner/smb/smb_version 3. msf auxiliary(smb_version) > set RHOSTS 172.16.62.1-200RHOSTS > 172.16.62.1-200msf auxiliary(smb_version) > set THREADS 100THREADS > 100msf auxiliary(smb_version) > run 4.扫描结果&#x…

算法(1)斐波那契数列

1.0 问题描述 实现斐波那契数列&#xff0c;求第N项的值 2.0 问题分析 斐波那契数列最简单的方法是使用递归&#xff0c;递归和查表法同时使用&#xff0c;可以降低复杂度。根据数列特点&#xff0c;同时进行计算的数值其实只有3个&#xff0c;所以可以使用3个变量循环递进计…

主键SQL教程–如何在数据库中定义主键

Every great story starts with an identity crisis. Luke, the great Jedi Master, begins unsure - "Who am I?" - and how could I be anyone important? It takes Yoda, the one with the Force, to teach him how to harness his powers.每个伟大的故事都始于…

算法(2)KMP算法

1.0 问题描述 实现KMP算法查找字符串。 2.0 问题分析 “KMP算法”是对字符串查找“简单算法”的优化。字符串查找“简单算法”是源字符串每个字符分别使用匹配串进行匹配&#xff0c;一旦失配&#xff0c;模式串下标归0&#xff0c;源字符串下标加1。可以很容易计算字符串查…

告别无止境的增删改查:Java代码生成器

对于一个比较大的业务系统&#xff0c;我们总是无止境的增加&#xff0c;删除&#xff0c;修改&#xff0c;粘贴&#xff0c;复制&#xff0c;想想总让人产生一种抗拒的心里。那有什么办法可以在正常的开发进度下自动生成一些类&#xff0c;配置文件&#xff0c;或者接口呢&…

Maven国内源设置 - OSChina国内源失效了,别更新了

Maven国内源设置 - OSChina国内源失效了&#xff0c;别更新了 原文&#xff1a;http://blog.csdn.net/chwshuang/article/details/52198932 最近在写一个Spring4.x SpringMVCMybatis零配置的文章&#xff0c;使用的源配的是公司的私有仓库&#xff0c;但是为了让其他人能够通过…

如何使用Next.js创建动态的Rick and Morty Wiki Web App

Building web apps with dynamic APIs and server side rendering are a way to give people a great experience both with content and speed. How can we use Next.js to easily build those apps?使用动态API和服务器端渲染来构建Web应用程序是一种使人们在内容和速度上都…

安装部署Spark 1.x Standalone模式集群

Configuration spark-env.sh HADOOP_CONF_DIR/opt/data02/hadoop-2.6.0-cdh5.4.0/etc/hadoop JAVA_HOME/opt/modules/jdk1.7.0_67 SCALA_HOME/opt/modules/scala-2.10.4 ####################################################### #主节点 …

算法(3)简单四则运算

1.0 问题描述 实现10以内四则运算&#xff08;只包含数字&#xff0c;*/和小括号&#xff09; 2.0 问题分析 四则运算使用“后缀表达式”算法来计算&#xff0c;后缀表达式可以无需考虑运算符优先级&#xff0c;直接从左至右依次计算。问题分解成2部分&#xff0c;一是将“中…

调用短信接口,先var_dump()看数据类型是object需要json_decode(json_encode( $resp),true)转换成array...

返回的数据.先看类型,如果是object类型 先json_encode, 再json_decode,加true 转换成数组 $resp $c->execute($req); var_dump($resp); object(stdClass)#12 (2) { ["result"]> object(stdClass)#13 (3) { ["err_code"]> string(1) "0"…

nlp文本数据增强_如何使用Texthero为您的NLP项目准备基于文本的数据集

nlp文本数据增强Natural Language Processing (NLP) is one of the most important fields of study and research in today’s world. It has many applications in the business sector such as chatbots, sentiment analysis, and document classification.Preprocessing an…

R语言-基础解析

二、操作基础%%取余%/%整数除法(1)eigen(...)求解方阵的特征值和特征向量(2)solve(D,A)求解DXA(3)data<-list(...)取里面的对象data[["列名称"]]&#xff1b;data[[下标]]&#xff1b;data$列名称(4)unlist(列表对象)把列表对象转化为向量对象(5)names(数据框)读取…

算法(4)数据结构:堆

1.0 问题描述 实现数据结构&#xff1a;堆。 2.0 问题分析 堆一般使用数组来表示&#xff0c;其中某个节点下标i的两个子节点的下标为 2i1 和 2i2。堆是一棵完全二叉树。堆有3种基本操作&#xff1a;创建&#xff0c;插入&#xff0c;删除。这3种操作都需要通过“调整堆”的…

cookie 和session 的区别详解

转自 https://www.cnblogs.com/shiyangxt/archive/2008/10/07/1305506.html 这些都是基础知识&#xff0c;不过有必要做深入了解。先简单介绍一下。 二者的定义&#xff1a; 当你在浏览网站的时候&#xff0c;WEB 服务器会先送一小小资料放在你的计算机上&#xff0c;Cookie 会…

如何设置Java Spring Boot JWT授权和认证

In the past month, I had a chance to implement JWT auth for a side project. I have previously worked with JWT in Ruby on Rails, but this was my first time in Spring. 在过去的一个月中&#xff0c;我有机会为辅助项目实现JWT auth。 我以前曾在Ruby on Rails中使用…

算法(5)哈希表

1.0 问题描述 实现数据结构&#xff1a;哈希表。 2.0 问题分析 哈希表可以看作我们经常使用的字典&#xff08;swift&#xff09;或对象&#xff08;js&#xff09;&#xff0c;可以让一个key&value对一一对应&#xff0c;可以快速根据key找到value。哈希表内部使用数组…

《面向对象程序设计》c++第五次作业___calculator plus plus

c第五次作业 Calculator plusplus 代码传送门 PS:这次作业仍然orz感谢一位同学与一位学长的windows帮助&#xff0c;同时再次吐槽作业对Mac系统用户的不友好。&#xff08;没朋友千万别用Mac&#xff01;&#xff01;&#xff01;&#xff09; 还有想吐槽作业对规范的要求大大超…

联合体union和大小端(big-endian、little-endian)

1.联合体union的基本特性——和struct的同与不同union&#xff0c;中文名“联合体、共用体”&#xff0c;在某种程度上类似结构体struct的一种数据结构&#xff0c;共用体(union)和结构体(struct)同样可以包含很多种数据类型和变量。在成员完全相同的情况下&#xff0c;struct比…

前端面试的作品示例_如何回答任何技术面试问题-包括示例

前端面试的作品示例Technical interviews can be extremely daunting. From the beginning of each question to the end, its important to know what to expect, and to be aware of the areas you might be asked about. 技术面试可能会非常艰巨。 从每个问题的开始到结束&a…

$(shell expr $(MAKE_VERSION) \= 3.81) 这里“\”的解释

android/build/core/main.mk $(shell expr $(MAKE_VERSION) \> 3.81) 为什么要加多一个“\”,因为">"会被shell解析为重定向符号&#xff0c;所以需要转义或用引号包围 所以&#xff0c;也可以这样写$(shell expr $(MAKE_VERSION) “>” 3.81)转载于:https:…

iOS应用模块化的思考及落地方案(一)模块的划分及模块化工作流程

1.0 什么是模块化 很多关于重构及设计模式的介绍中&#xff0c;经常提到的几个词语是复用及解耦。 模块化之所以被提出&#xff0c;也更多是为了解决这几个问题。 复用可以减少重复造轮子的情况&#xff0c;很容易理解的是&#xff0c;我们经常使用的github上的第三方框架&a…

Swiper 用法

部分常用API ininialSlide: 2, //起始图片切换的索引位置&#xff08;起始从0开始&#xff0c;默认为0&#xff09; autoplay: 3000, //设置自动切换时间&#xff0c;单位毫秒 speed: 1000, //设置滑动速度 continuous: true, //无限循环的图片切换效果 disableScroll: true, /…

node/js 漏洞_6个可用于检查Node.js中漏洞的工具

node/js 漏洞Vulnerabilities can exist in all products. The larger your software grows, the greater the potential for vulnerabilities. 所有产品中都可能存在漏洞。 您的软件增长得越大&#xff0c;潜在的漏洞就越大。 Vulnerabilities create opportunities for expl…

发现一个浏览器很奇怪的问题

浏览器有8个请求状态为pending时&#xff0c;在另一个tab中&#xff0c;请求就发布出去了&#xff0c;一直是stalled。直到pending状态变成了cancled状态。 试了360浏览器&#xff08;谷歌内核&#xff09;和chrome浏览器&#xff0c;都是这样。 具体的原因待深究 参考&#xf…

wamp配置虚拟主机

因为wampserver的php版本一直是5.x版本&#xff1b;因此转投xmapp用了一段时间&#xff1b; 意外发现wampserver3更新了&#xff1b;php也终于更新到7了&#xff1b; 果断还是决定回到wampserver的怀抱&#xff1b; 然后有意外的发现了wampserver3有了新功能&#xff1b;可以方…

iOS应用模块化的思考及落地方案(二)模块化自动构建工具的使用

1.0 iOS模块化中的问题 前文已经介绍了模块化的流程及一些常见的问题&#xff0c;我们在这里再次总结一下。 在工作中&#xff0c;当我们开始一个新项目的时候&#xff0c;最先考虑的就是模块化工作。 模块化工作的想法是很美好的&#xff0c;可是执行过程中会遇到很多的问题…

aws fargate_我如何在AWS Fargate上部署#100DaysOfCloud Twitter Bot

aws fargateAfter passing my last certification, I asked myself how much time I spent studying cloud computing.通过上一份认证后&#xff0c;我问自己自己花了多少时间研究云计算。 More than 100 days!超过100天&#xff01; It also made me realize two things:这也…