Jump to content

Hello everyone,

 

I have a problem in a program and I was hoping you could help.

 

So, I have a Set of users (Set<users>) with lines like this:

nick0,mail_0_@sapo.pt,city4,city6
nick7,nick4,nick3
nick1,mail_1_@sapo.pt,city5,city9,city4
nick6,nick2,nick8

...

 

Where the first line has: the nickname of the user, the email and from this point on the different cities that he has been in.

The second line is for the friendships of that user which don't matter for this problem.

 

Now I have to see, for each of the existing cities, which user visited it the most times, the one who has visited the most times will be given the status of "mayor".

 

I have no idea what structures to use so I can store the different points for each user and city, and then compare the points of the users for each city.

 

Appreciate any help

(Sorry if bad english)

Link to comment
https://linustechtips.com/topic/677414-3-collum-structure-in-java/
Share on other sites

Link to post
Share on other sites

I'll use python as that's what I use most but should be somewhat the same. You will need a list where each item is a dictionary and to which the city is also a dictionary 

 

myDict = [
	{
		'username':'user1', 
		'email':'useremail@gmail.com', 
		'citys':{'gington':2,'differspace':1}
	},
	{
		'username':'user2',
		'email':'user2@email.com',
		'citys':{'gington':1,'differspace':2}
	}
	]
print(myDict[0]['username'])
print(myDict[0]['email'])
#these are the users visits
print(myDict[0]['citys']['gington'])
print(myDict[0]['citys']['differspace'])
#second user
print(myDict[1]['username'])
print(myDict[1]['email'])
#these are the users visits
print(myDict[1]['citys']['gington'])
print(myDict[1]['citys']['differspace'])

 Output

Quote

user1
useremail@gmail.com
2
1
user2
user2@email.com
1
2
 
 

So you would loop the list and then compare each of the myDict['citys']['name'] so get the count and then whoever has most give them the title. You will need to add major as an item too.

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to post
Share on other sites

15 minutes ago, vorticalbox said:

I'll use python as that's what I use most but should be somewhat the same. You will need a list where each item is a dictionary and to which the city is also a dictionary 

 


myDict = [
	{
		'username':'user1', 
		'email':'useremail@gmail.com', 
		'citys':{'gington':2,'differspace':1}
	},
	{
		'username':'user2',
		'email':'user2@email.com',
		'citys':{'gington':1,'differspace':2}
	}
	]
print(myDict[0]['username'])
print(myDict[0]['email'])
#these are the users visits
print(myDict[0]['citys']['gington'])
print(myDict[0]['citys']['differspace'])
#second user
print(myDict[1]['username'])
print(myDict[1]['email'])
#these are the users visits
print(myDict[1]['citys']['gington'])
print(myDict[1]['citys']['differspace'])

 Output

So you would loop the list and then compare each of the myDict['citys']['name'] so get the count and then whoever has most give them the title. You will need to add major as an item too.

Thank you for the reply

 

So you are saying that I should have two maps (Java Structures) where one of them has the name of the city as a key and the value as another structure linking the names of the users to the city points.

However there are multiple cities for wich the user will have different points (points are the times that the user has visited)

 

Or do you suggest another better way of doing so?

 

I am sorry if I didn't understand your reply

Link to post
Share on other sites

6 minutes ago, ShatteredPsycho said:

Thank you for the reply

 

So you are saying that I should have two maps (Java Structures) where one of them has the name of the city as a key and the value as another structure linking the names of the users to the city points.

However there are multiple cities for wich the user will have different points (points are the times that the user has visited)

 

Or do you suggest another better way of doing so?

 

I am sorry if I didn't understand your reply

my code has two citys and each user has different points.

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×