一组字符串给出两种排列方式,

求最小分成多少组 如

A     A

B     C

C    D

D    B

E    E

则分成3组

A

B C D

E

即为1 3 1

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
map <string, int> maps;
int main()
{
int T;
cin >> T;
while(T--)
{
int n;
//char s[11];
cin >> n;
maps.clear();
string s;
for(int i = ; i < n; i++)
{
cin >> s;
//maps.insert(pair<string, int>(s, i));
maps[s] = i;//map把一个s和i对应起来
}
int ans = , idx = ;
for(int i = ; i < n; i++)
{
cin >> s;
/*map<string, int>::iterator iter;
iter = maps.find(s);
int t = iter -> second;*/
int t = maps[s];
idx = max(idx, t);
ans++;
if(idx == i) printf("%d ", ans), ans = ;
}
printf("\n");
}
return ;
}

最新文章

  1. 最近在新公司的一些HTML学习
  2. Linux IPC Pipe
  3. Android系统截屏的实现(附代码)
  4. POJ2299Ultra-QuickSort(归并排序 + 树状数组求逆序对)
  5. RMAN - 备份异机恢复
  6. 开源API测试工具 Hitchhiker v0.6更新 - 改进压力测试
  7. ubuntu16.04中supervisor安装与简单使用(转载)
  8. VUE踩坑之路
  9. 数据结构树之AVL树(平衡二叉树)
  10. 高DPI下界面错乱的解决方法和原理
  11. learning to generate question headlines 讲座
  12. mysql5.7.20安装
  13. PyQT5速成教程-1 简介与环境搭建
  14. Linux下使用wget下载FTP服务器文件
  15. QT1.1-与Opencv的hello world
  16. 每日英语:How Your Knees Can Predict the Weather
  17. Python数据结构算法
  18. gcc 与 g++的区分较
  19. DDR3调试记录
  20. 软件系统分析师与架构师技能大PK(您具备了哪些呢?)

热门文章

  1. 国外、国内各大OJ
  2. 019--python内置函数
  3. css里关于浏览器的前缀
  4. git&#160;基本命令详细解释
  5. poj1308【并查集】
  6. OpenCV认识之发展历史
  7. hdu1102 Constructing Roads 基础最小生成树
  8. 跟我一起玩Win32开发(3):窗口的重绘
  9. [LOJ6041雅礼集训2017]事情的相似度
  10. 题解报告:hdu 4607 Park Visit(最长链)