STL || Gym 101653U Top 25
2024-09-03 02:35:24
一组字符串给出两种排列方式,
求最小分成多少组 如
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 ;
}
最新文章
- 最近在新公司的一些HTML学习
- Linux IPC Pipe
- Android系统截屏的实现(附代码)
- POJ2299Ultra-QuickSort(归并排序 + 树状数组求逆序对)
- RMAN - 备份异机恢复
- 开源API测试工具 Hitchhiker v0.6更新 - 改进压力测试
- ubuntu16.04中supervisor安装与简单使用(转载)
- VUE踩坑之路
- 数据结构树之AVL树(平衡二叉树)
- 高DPI下界面错乱的解决方法和原理
- learning to generate question headlines 讲座
- mysql5.7.20安装
- PyQT5速成教程-1 简介与环境搭建
- Linux下使用wget下载FTP服务器文件
- QT1.1-与Opencv的hello world
- 每日英语:How Your Knees Can Predict the Weather
- Python数据结构算法
- gcc 与 g++的区分较
- DDR3调试记录
- 软件系统分析师与架构师技能大PK(您具备了哪些呢?)