OR78. 组件灰度发布
描述
输入描述
输入有多行,每一行表示用户ID范围和对应的组件ID输出描述
输出有多行,每一行表示用户ID范围和对应的组件列表,范围从小到大排序,各个数字之间用空格隔开,行末无空格示例1
输入:
1 10 1 5 20 2 15 25 3
输出:
1 4 1 5 10 1 2 11 14 2 15 20 2 3 21 25 3
C++ 解法, 执行用时: 2ms, 内存消耗: 376KB, 提交时间: 2020-10-31
#include <iostream> #include <vector> #include <algorithm> using namespace std; typedef struct number{ //int Count=0;//ID数量 string Id=""; }Num; int main() { Num num[100]; char id; int j=1; int IdFirst,IdEnd,IdMax=0,IdMin=0; cin>>IdFirst>>IdEnd>>id; IdMax = IdEnd; IdMin = IdFirst; for(int i=IdFirst;i<=IdEnd;i++) { //num[i].Count++; num[i].Id += " "; num[i].Id += id; } while(cin>>IdFirst>>IdEnd>>id) { j++; if(IdMax<IdEnd) IdMax = IdEnd; if(IdMin>IdFirst) IdMin = IdFirst; for(int i=IdFirst;i<=IdEnd;i++) { //num[i].Count++; num[i].Id += " "; num[i].Id += id; } if(j>=3) break; } string IDs = num[IdMin].Id; int Begin = IdMin,End; for(int k=IdMin;k<=IdMax;k++) { if(IDs!=num[k].Id) //找到区间 {End = k-1; if(num[k-1].Id!="") cout<<Begin<<" "<<End<<num[k-1].Id<<endl; Begin = k;IDs = num[k].Id; } if(k == IdMax) cout<<Begin<<" "<<k<<num[k].Id<<endl; } }
C++ 解法, 执行用时: 2ms, 内存消耗: 376KB, 提交时间: 2020-10-31
#include <iostream> #include <vector> #include <algorithm> using namespace std; typedef struct number{ //int Count=0;//ID数量 string Id=""; }Num; int main() { Num num[100]; char id; int j=1; int IdFirst,IdEnd,IdMax=0,IdMin=0; cin>>IdFirst>>IdEnd>>id; IdMax = IdEnd; IdMin = IdFirst; for(int i=IdFirst;i<=IdEnd;i++) { //num[i].Count++; num[i].Id += " "; num[i].Id += id; } while(cin>>IdFirst>>IdEnd>>id) { j++; if(IdMax<IdEnd) IdMax = IdEnd; if(IdMin>IdFirst) IdMin = IdFirst; for(int i=IdFirst;i<=IdEnd;i++) { //num[i].Count++; num[i].Id += " "; num[i].Id += id; } if(j>=3) break; } string IDs = num[IdMin].Id; int Begin = IdMin,End; for(int k=IdMin;k<=IdMax;k++) { if(IDs!=num[k].Id) //找到区间 {End = k-1; if(num[k-1].Id!="") cout<<Begin<<" "<<End<<num[k-1].Id<<endl; Begin = k;IDs = num[k].Id; } if(k == IdMax) cout<<Begin<<" "<<k<<num[k].Id<<endl; } }