Queue
Input:
A, B, C, D, E ...
1/1
1/2
2/3
3/4
2/5
Output (Queue!):
5 B
1 E
3 C
4 D
2 A
How to make this?
Mark competitors (persons) Example: A ... E their come in first queue.
A can label/tag 1/1. B can label 1/2, consequently at this moment hierarchy B, A. Next C can label 2/3, consequently hierarchy B,C,A .
Then D can label 3/4, and hierarchy is B, C, D, A.
Finally can E label 2/5, which means, et finally hierarchy is B, E, C, D, A.
Using (linked list, queue, map?) Any ideas? How to solve this task?
Thanks.
My bad english!
-ordi-
Junior Poster in Training
92 posts since Dec 2009
Reputation Points: 18
Solved Threads: 11
I have no idea what you are trying to do. A better or more detailed example is needed.
My bad english!
You don't say! :icon_wink:
We can get over that...
WaltP
Posting Sage w/ dash of thyme
10,505 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
#include <iostream>
#include <fstream>
using namespace std;
// Esimesed 6 testi lahendab antud aja piires
int n;
struct Sportlane
{
//int name;
int pos;
};
int main()
{
ifstream sisf("prottest.06.sis");
ofstream valf("prot.val");
sisf >> n;
char k; int b;
struct Sportlane sportlane[n];
for (int i = 1; i <= n; i++)
{
sisf >> sportlane[i].pos >> k >> b;
//sportlane[i].name = i;
}
for (int i = 1; i <= n; i++)
{
for (int j = i; j <= n; j++)
{
if (sportlane[j].pos <= sportlane[i].pos && i != j)
{
sportlane[i].pos = sportlane[i].pos + 1;
}
}
}
// Väljastame
for (int i = 1; i <= n; i++)
{
valf << sportlane[i].pos << endl;
}
return 0;
}
Ok my solution, it's little bit slow of course.
prot.sis
5
1/1
1/2
2/3
3/4
2/5
prot.val
5
1
3
4
2
-ordi-
Junior Poster in Training
92 posts since Dec 2009
Reputation Points: 18
Solved Threads: 11