0

I just joined this website :) I am a beginner and I had a problem. I have two arrays a [n] and b[n]. for example :

n = 3
3 10
6 5
2 30

The first column is array a and the second is array b. I sort array b but I need array a [i] to be for array b[i] after sorting . what can I do ? I mean : b = 30, 10, 5 (after sorting) now a[0] = 3 and b [0] = 30 but I want it to be like this : a[0] = 2 b[0] = 30 I hope you could understand it Thanks In advance :)

I need array a to be relevant to array b please help me

463035818_is_not_an_ai
  • 109,796
  • 11
  • 89
  • 185
Marya
  • 11
  • 1
  • What did you try so far? Looks like homework. We're willing to help you but at least you should try – Robert Kock Mar 23 '22 at 10:44
  • I will type my explanation now : the problem : someone wants to do some work but he has just s hours empty to do them. There are n tasks that each of them takes a specific time from him and also he earns money by doing them. He wants to earn the highest money. My solution : We have to sort the money from greatest tosmallest and I did it. After that we have to see whether the time of each isn't higher than the time left or not. But I don't know how to keep the time array for the money array after sorting?? – Marya Mar 23 '22 at 10:54
  • Please provide enough code so others can better understand or reproduce the problem. – Community Mar 23 '22 at 10:57
  • https://pastebin.ubuntu.com/p/J6RC4bBTwf/ – Marya Mar 23 '22 at 11:33
  • This is my code , The problem that I have is written in the comment in the for loop – Marya Mar 23 '22 at 11:34
  • Code should go in question, not external link. Anyway, this is duplicate. One of many duplicates. See the linked Q&A regarding how to sort two arrays that are related. – paddy Mar 23 '22 at 11:38
  • Thanks for your help. It was my first day that I joined this website and I am also young so I didn't know that I can put my code there. Thanks anyway :) – Marya Mar 23 '22 at 11:54

0 Answers0