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