Tag Archives: 2033 Devices

2033: Devices

https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js

Problem Link

Tutorial

Here , today I’ll discuss about the problem .
The main point of the problem is to determine the numbers of modern devices that his friends have.

And he will buy the device that is used by maximum numbers of his friend.
From this overview, we have got some hints about determining the occurrence of modern devices.

if there are several devices that occupy max number of times, then he will buy the cheapest one.

 

Code in brief

I used two map ,one will store the frequency and another will update the minimum cost of the device to find the cheapest one .
That’s it 🙂

 

 

View Code

#include
#include
#include
#include
#include
#include

using namespace std;

int main()
{
	int ok=0,mx=0,mn=(int)1e9,k;
	string ans;
	string x,y;
	map mp;
	map mpp;
	for(int i=0;i>x>>y>>k;
		if(!mp.count(y))
			mp[y]++,mpp[y]=k;
		else{
			mpp[y]=min(k,mpp[y]),mp[y]++;
		}
                ok=max(ok,mp[y]);
	}
	for(auto it : mp)
	{
		 if(it.second==ok)
		 {
			if(mpp[it.first]<=mn)
			{
				ans=it.first;
				mn=mpp[it.first];
			}
		}
	}
	cout<<ans<<'\n';
}