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!

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...

Correct me if I am wrong, but it looks to me like what you would like to do is something like this. The inputs are labeled A, B, C, D, and E, respectively. So your first input is the rank of where A is, out of the total amount. So if you put in 1/1, that means that A comes 1st out of 1. Your next input will be for B's rank. B is first now, so we put in 1/2, 1st out of 2 total (A and B). When you input C's rank, it will be second out of the total number of ranks input so far, which is 2/3.

Is that right? If so, then I don't think you even need to put the / and the 2nd number, just keep a count of the total. You could start with your 5 variables and input their ranks in order, then figure out which order to display them in. A sort would work, I think.

Or instead of a sort, I know this will work (because I just wrote a program to do this).

Each time the user inputs another value for your variable, check to see if it's <= each of the other variables. If so, increment that variable by one.

cin>>c;

if(c<=a){
    a++;
}
if(c<=b){
    b++;
}

Then when you are done, they will already be in order.

You can use an array of chars or strings, and assign the values like:

ary[a] = 'A';
ary[b] = 'B';

etc.

There's probably a better way of solving this, but oh well. This works.

#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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.