(使用STL中的数据结构进行编程7.3.15)UVA 630 Anagrams (II)(求一个单词在字典中出现的次数)
2024-10-14 12:47:06
/*
* UVA_630.cpp
*
* Created on: 2013年11月4日
* Author: Administrator
*/ #include <iostream>
#include <cstdio>
#include <map>
#include <string>
#include <algorithm> using namespace std; int main(){
int t;
scanf("%d",&t);
while(t--){
multimap <string,string> mp;
string str; int n;
scanf("%d",&n); int i;
for(i = 0 ; i < n ; ++i){
cin >>str; string temp = str;
sort(temp.begin(),temp.end());
mp.insert(make_pair(temp,str));//map中保存的数据形式是(有序串,原串) 有序串用于比较,原串用于输出
} while(cin >> str,str != "END"){ string tp = str;
sort(tp.begin(),tp.end()); cout<<"Anagrams for: "<<str<<endl;
int count = 1;
bool flag = false;
for(map<string,string>::iterator it = mp.begin() ; it != mp.end() ; ++it){
if(tp == (*it).first){
flag = true;
printf("%3d) %s\n",count++,(*it).second.c_str());
}
} if(flag == false){
cout<<"No anagrams for: "<<str<<endl;
}
} if(t){//注意:千万别漏了,测试数据之间要输出空行...
cout<<endl;
}
} return 0;
}
最新文章
- Method Swizzling (方法调配)
- Spring MVC + MyBatis整合(IntelliJ IDEA环境下)
- PL/SQL之--包
- hduoj 4712 Hamming Distance 2013 ACM/ICPC Asia Regional Online —— Warmup
- XE2编译出来的DLL的DLLMain的退出地方用到了halt0
- *****正则表达式匹配URL
- 腾讯云中ssL证书的配置安装
- ImCash:币安下架BSV之辩:规则、中立与去中心化
- wangEditor的使用
- Django 项目内利用ORM直接运行脚本读库
- MACD各分时背离所对应的时间
- [转]RabbitMQ系列(一):Windows下RabbitMQ安装及入门
- log4j.properties配置文件详解
- vscode调试js,安装了nodejs之后还出现无法在Path上找到运行时的node
- HTTP监视器charles入门使用教程分享---http/s packet monitors---ubuntu installation
- 利率计算v4.0--测试--软件工程
- MySQL Error: PROCEDURE xmdk.query_all_plan can&#39;t return a result set in the given context
- Git使用技巧(3)-- 远程操作
- 浏览器指纹--纯js拿到浏览器指纹
- ndarray:一种多维数组对象
热门文章
- 【Vue实战之路】一、Vue-cli入门及Vue工程目录全解。
- 二叉查找树(二叉排序树)的详细实现,以及随机平衡二叉查找树Treap的分析与应用
- Linux下实现自动设置SSH代理
- 一个页面从输入 URL 到页面加载显示完成,这个过程中都发生了什么?
- Codeforces Round #374 (Div. 2) C. Journey DP
- Codeforces Round #258 (Div. 2) C. Predict Outcome of the Game 水题
- CentOS下多网卡绑定多IP段时导致只有一个会通的问题解决
- KVM磁盘镜像qcow2、raw、vmdk等格式区别(转)
- 【转】JavaScript eval处理JSON数据 为什么要加括号
- 通过WinAPI播放PCM声音