当前位置:网站首页>L2-039 清点代码库 (25 分)
L2-039 清点代码库 (25 分)
2022-04-21 11:22:00 【pace_the】
重点: vector可以直接比较大小,就像string比较大小一样。也可以放map键值位置自动排序。
vector里放结构体,对vector的内容进行排序,需要重载结构体比较<运算符。里面也涉及到vector排序,如上述。
题面:
上图转自新浪微博:“阿里代码库有几亿行代码,但其中有很多功能重复的代码,比如单单快排就被重写了几百遍。请设计一个程序,能够将代码库中所有功能重复的代码找出。各位大佬有啥想法,我当时就懵了,然后就挂了。。。”
这里我们把问题简化一下:首先假设两个功能模块如果接受同样的输入,总是给出同样的输出,则它们就是功能重复的;其次我们把每个模块的输出都简化为一个整数(在 int 范围内)。于是我们可以设计一系列输入,检查所有功能模块的对应输出,从而查出功能重复的代码。你的任务就是设计并实现这个简化问题的解决方案。
输入格式:
输入在第一行中给出 2 个正整数,依次为 N(≤104)和 M(≤102),对应功能模块的个数和系列测试输入的个数。
随后 N 行,每行给出一个功能模块的 M 个对应输出,数字间以空格分隔。
输出格式:
首先在第一行输出不同功能的个数 K。随后 K 行,每行给出具有这个功能的模块的个数,以及这个功能的对应输出。数字间以 1 个空格分隔,行首尾不得有多余空格。输出首先按模块个数非递增顺序,如果有并列,则按输出序列的递增序给出。
注:所谓数列 { A1, ..., AM } 比 { B1, ..., BM } 大,是指存在 1≤i<M,使得 A1=B1,...,Ai=Bi 成立,且 Ai+1>Bi+1。
输入样例:
7 3
35 28 74
-1 -1 22
28 74 35
-1 -1 22
11 66 0
35 28 74
35 28 74
输出样例:
4
3 35 28 74
2 -1 -1 22
1 11 66 0
1 28 74 35
代码:
仿照下链接,可以对比代码,链接中的更简洁qwq
(10条消息) 天梯赛--L2-039 清点代码库 (25 分)_wowon~的博客-CSDN博客
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
map<vector<int>,int>mp;
struct node{
int cnt;
vector<int>v;
bool operator<(const node& b){
if(cnt==b.cnt){
return v<b.v;
}else{
return cnt>b.cnt;
}
}
};
vector<node>ans;
int main (){
int n;int m;
cin>>n>>m;
int i,j;
for(i=0;i<n;i++){
vector<int>v(m);
for(j=0;j<m;j++){
cin>>v[j];
}
mp[v]++;
}
int top=1;
for(auto it=mp.begin();it!=mp.end();it++){
node tmp;
tmp.v=it->first;
tmp.cnt=it->second;
ans.push_back(tmp);
}
sort(ans.begin(),ans.end());
cout<<(int)mp.size()<<endl;
for(i=0;i<(int)ans.size();i++){
cout<<ans[i].cnt<<" ";
for(j=0;j<(int)ans[i].v.size();j++){
if(j>0)cout<<" ";
cout<<ans[i].v[j];
}
cout<<endl;
}
// for(i=1;i<top;i++){
// cout<<nd[i].cnt<<" ";
// for(j=0;j<(int)nd[i].v.size();j++){
// if(j>0)cout<<" ";
// cout<<nd[i].v[j];
// }
// cout<<endl;
// }
return 0;
}
版权声明
本文为[pace_the]所创,转载请带上原文链接,感谢
https://blog.csdn.net/ale_upcer/article/details/124222158
边栏推荐
- Decorator modifier / binary array of ES6 new feature (8)
- Matlab GUI --- piczoom animation demonstration
- 实现浏览器多标签页通信
- 以用户体验五要素的思路,如何编写产品需求文档(PRD)
- 产品分享:Qt+OSG教育学科工具之地理三维星球
- Digital IT operation from the perspective of thinking transformation
- Development of digital collection platform and construction of digital collection app
- 1. Precision marketing practice Alibaba cloud odpscmd precision marketing data processing
- New features of ES6 (7): proxy proxy / model module / import / export
- redis面试问题
猜你喜欢

Spark快速入门系列(5) | Spark环境搭建—standalone(2) 配置历史日志服务器

Unix哲学与高并发

How does IOT platform realize business configuration center

你的思维会改变你的行为,你的行为会改变你的境遇

循环队列的长度「In DataStructure」

犀牛软件插件-rhino插件-visual studio-创建你的第一个插件
![[interview ordinary people vs Expert Series] understanding of B tree and B + tree](/img/17/a81da0a2e6b0c7cb218879f1a79861.jpg)
[interview ordinary people vs Expert Series] understanding of B tree and B + tree

连接服务器报错No supported authentication methods available

左程云 - 大厂刷题班 - 绳子覆盖最多的点

stm32i2c的解答
随机推荐
54000 stars all return to zero. Project Author: I regret it very much
js---call,apply,bind
犀牛软件插件-rhino插件-visual studio-创建你的第一个插件
AD中如何在3D下生成PCB实时快照
打开应用出现 “需要使用新应用一打开此ms-gamingoverlay链接”
现在有没有可以真正称得上是元宇宙的应用?
借助 cryptojs实现 AES 加解密
以用户体验五要素的思路,如何编写产品需求文档(PRD)
MQ相關流程及各項內容
Tami dog knowledge | what are the legal procedures for equity transfer?
MQ相关流程及各项内容
Internet News: tuojing technology successfully landed on the science and innovation board; Jimi h3s and z6x Pro continue to sell well; HEMA launches "mobile supermarket" in Shanghai
Matlab GUI --- subject selection (animation demonstration)
UNIX philosophy and high concurrency
How does the webmaster prevent the website from being hacked
Introduction to Alibaba's super large-scale Flink cluster operation and maintenance system
Simple threading - using threads to run multiple browsers easily
ES6新特性(7)之Proxy代理/Model模块/import/export
Question brushing & Competition & Review
程序员如何确保软件没 Bug?