Ignoring particular arrays in loop after conditions are met once / sorting arrays

Hi,
I can't really find a tutorial which would give this info.
I have a text file:


14
4 1 25
4 1 13
4 2 15
4 2 25
3 2 42
3 2 25
4 1 25
3 1 25
4 1 25
3 1 42
3 1 25
3 1 36
4 1 24
4 1 15


14 - number of shoes
each other line:
3 or 4 indicates type of shoes (3-men shoe; 4-women shoe)
1 or 2 - left or right shoe
the fird number is the size of particular shoe.

All I need to do is calculate how many there are identical pairs of each men and women shoes (the answer is 2 pairs men + 2 pairs women).

It's purely a question of properly using syntax... And they say programming is about maths... egh.. :D

The obvious thing, reading, is there:
1
2
3
4
5
6
7
8
void skaitymas (int gender[], int leg[], int size[])
{
    ifstream failas("a.txt");
    int n;
    failas >> n;
    cout << n << endl;
    for (int i=0; i<n; i++){
        failas >> gender[i] >> leg[i] >> size[i];


But what's next? Maybe some "if" with char:
1
2
if(gender[i]=3){
        gender[i]=men;
?

But to be honest it doesn't look right :D

How do I sort those values ?
How to write a code for finding the same ones?

I need to figure it out cause basically all the exercises I'am going to do in my exam are purely related to this one. They are often obvious to solve, but tricky to write, heh...

Thanks in advance.

EDIT:
Ok with a bit of help I made it.

EDIT2: sh1t, not yet ...


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

void skaitymas (int lytis[], int koja[], int dydis[])
{
    ifstream failas("a.txt");
    int z=0;
    int n;
    failas >> n;

    for (int i=0; i<n; i++){
        failas >> lytis[i] >> koja[i] >> dydis[i];

    for (int k=i+1; k<n-1; k++){
        failas >> lytis[k] >> koja[k] >> dydis[k];

        if(   (lytis[i] == 3) &&  (lytis[i] == lytis[k] ) && (koja[i] == koja[k]) && (dydis[i] == dydis[k])){

    z=z+1;
        cout << z << endl;;

        }}}
            failas.close();}





lytis - gender
koja - leg (left right)
dydis - size
mot - women sh
Last edited on
I recommend you show your complete program.

How are gender, leg, size defined in the calling function?

How is the variable men defined? What would be the purpose of the re-assignment?

You know that the number three means "men's shoe" and the number four means "womans shoe" so why do you need to try to redefine that meaning?

Well, reading function is all I did right, after that the following code is just a hit and miss cause I basically have no idea how to tell compiler to find similiar lines and filter out unneeded data.

I thought I will somehow store needed values in other variables (if array[i]=y, then array[i]=x, so the unneded ones would be filtrated), as we don't know which [i] array is the needed one to call for it later , but I feel it isn't the right way to do it.
Last edited on
Any ideas?
How do I tell compiler to seperate needed values and hold them in one place?
Last edited on
Aghh...

Just when I thought everything is done, a new issue popped out...

You see I have a 3 similiar lines:

4 1 25
4 1 13
4 2 15
4 2 25
3 2 42
3 2 25
4 1 25
3 1 25
4 1 25
3 1 42
3 1 25
3 1 36
4 1 24
4 1 15


The idea of my code is to search for similiar lines and if one line is found to be the exact same as any other line, variable gets value++, so if there are 2 similiar lines, the variable would get a value of 1 (pair of shoes).

now the problem is, with 3 identical lines, the variable becomes also 3, because it calculates 1l=2l; 1l=3l; 2l=3l;

How do I tell it to break this type of calculations when more than 2 identical lines are found?

Maybe somehow delete/filter out the detected pairs of lines from the checking list after giving variable++ while loop is running? No idea how to code that.
Last edited on
bump
I'am surprised no one came up with an answer, as all I had to do is write
1
2
 lytis[i]=0;
            lytis[k]=0;

to give in loop an already used array a unusable value so that compiler won't be using again the same line.




Whole calculating code for women shoes:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
    for (int i=0; i<n; i++){
        failas >> lytis[i] >> koja[i] >> dydis[i];

    for (int k=i+1; k<n-1; k++){
        failas >> lytis[k] >> koja[k] >> dydis[k];

        if(   (lytis[i] == 3) &&  (lytis[i] == lytis[k] ) && (koja[i] == koja[k]) && (dydis[i] == dydis[k])){

    vyr=vyr+1;}

        if(   (lytis[i] == 4) &&  (lytis[i] == lytis[k] ) && (koja[i] == koja[k]) && (dydis[i] == dydis[k])){

            mot=mot+1;
            lytis[i]=0;
            lytis[k]=0;


     }


        }} 


lytis - gender
koja - leg (left right)
dydis - size
mot - women sh
Last edited on
Topic archived. No new replies allowed.