echang
BAN USER
My solution:
#include <iostream>
#include <list>
#include <algorithm>
using namespace std;
int main()
{
list<int> alist={1,2,4,5,7,8,12};
int K=4;
int num=alist.size();
int Kx=min(K, num-K+1);
int Ky=max(K, num-K+1);
list<int>::iterator tmp_it, it;
int val, n;
for (it=alist.begin(), n=1; it != alist.end(); ++it, ++n){
if(n==Kx) tmp_it = it;
if(n==Ky) {val=*tmp_it; *tmp_it=*it; *it=val;}
}
for(auto it: alist) cout << it <<" ";
cout << endl;
}
/*
1 2 4 5 7 8 12
*/
My solution -- it is easy to understand:
#include <array>
#include <map>
#include <iostream>
using namespace std;
int main()
{
array<int,4> arr={570,675,990,690};
array<int,4> dep={705,690,1005,1005};
map<int,int> seq;
pair<map<int,int>::iterator, bool> ret;
for (auto it: arr) {
ret = seq.insert(pair<int, int>(it, 1));
if (ret.second == false) seq[it]++;
}
for (auto it: dep) {
ret = seq.insert(pair<int, int>(it, -1));
if (ret.second == false) seq[it]--;
}
int gates=0;
int temp=0;
for (auto& kv: seq){
cout << kv.first << " => " << kv.second << endl;
temp += kv.second;
if (temp > gates) gates = temp;
}
cout << "We need gates: " << gates << endl;
}
/* output:
570 => 1
675 => 1
690 => 0
705 => -1
990 => 1
1005 => -2
We need gates: 2
*/
RepLisaTQuinn, Analyst at A9
I have a passion for reading and creative writing and attend many workshops and conventions surrounding love spell that work ...
Repnickjonson885, Consultant at ASU
I am Department director in a Libera company. I live in Buffalo NY, USA. I am a hard worker girl ...
RepAvyuktBurk, photographer at Precious Moments
Confident and dedicated photographer with experience in both professional and freelance photography. I like to explore Black Magic Spell To ...
RepLauraJOles, Android Engineer at A9
Hi i am Laura.I live in Us from my childhood and i love my country.My father he is ...
Repselindareese, Animator at Agilent Technologies
I am Selinda a Music teacher and composer with 6+ years of experience with an in depth knowledge of music ...
RepHi, I am Maria from Worcester, USA. I have been working as a Blogger in Enticing Express from last 2 ...
Repshanitajjana, +27655765355 SSD MONEY CLEANING CHEMICAL +27655765355 BLACK MONEY IN JOHANNESBURG, OMAN, SAUDI ARABIA, SUDAN, Somalia ,Zimbabwe Botswana at 247quickbookshelp
Hi I am Shanita from San Bernardino USA. I am working as a manager in flore company. I am outgoing ...
RepRuthMitchell, Applications Developer at ASAPInfosystemsPvtLtd
My name is Mitchell working as a technical sales support worker in the USA. I identify and establish new business ...
Repkenneroce, Cheap Escort Service in Lajpat Nagar 8447779280 Call Girls at Persistent Systems
Hi, I am Kenne working as a LAN manager. One day, I read how to break up a couple from ...
Rephazelwlson80, abc at A9
I am a skilled civil engineer with many years of experience in a variety of engineering aspects. There are a ...
Repjoankelly306, Site Manager at EFI
Hi, I am Joan from Fairbanks, in USA. I have been a Food Product Manager in a Food Barn Company ...
Repshirleyjbarker439, Animator at ASAPInfosystemsPvtLtd
Hello, I am Gladys. I am a Industrial Photographer. I started off my photographic career as a News photographer based ...
Repjacksabjohne, Accountant at ABC TECH SUPPORT
Michael is a Biological Technician with 4 years of experience monitoring, characterizing, and quantifying riverine processes and habitat in the ...
Repshawt146, Applications Developer at ADP
I love Exploring and photography. I want to fill my life with happiness and beautiful mammaries. I also like to ...
Repdebbiewilsond, Software Trainee at Electronic Arts
I am Debbie from Nashua in Us.I Done my study from Us university .Now I am working in Science ...
Repman254183, Project Leader at GoDaddy
I am working as Human Resources Associates, and my duties are for obtaining, recording, and interpreting human resources information within ...
Repcolettehenna, OOPS Freshers at Bosch
I am Colette , policy analyst at Sunflower Market , with 3 years of experience building and maintaining relationships with elected officials ...
Reptaylamowll, Analyst at AMD
Aspire to work in a challenging environment, where my exceptional skills and abilities are completely explored, and I can easily ...
RepGiannaDavid, Author at The times
I am an Author, I have a passion for reading and creative writing and attend many workshops and conventions surrounding ...
Repteresawells858, Java Developer at 247quickbookshelp
I am Teresa. I work as a Software engineer at Asian Fusion Company. I was born in the US and ...
My c++ solution without recursion:
Here are outputs:
- echang October 06, 2016A
B
C
D
AB
AC
AD
BC
BD
CD
ABC
ABD
ACD
BCD
ABCD