Skip to content

Instantly share code, notes, and snippets.

@dazza
Created July 10, 2009 07:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dazza/144306 to your computer and use it in GitHub Desktop.
Save dazza/144306 to your computer and use it in GitHub Desktop.
#include <cstdio>
#include <string>
#include <vector>
using namespace std;
class RectangleGroups
{
public:
string maximalIndexed(vector<string> rectangles)
{
int abcIndex[26] = {0};
char g;
int w,h;
for (size_t i = 0; i<rectangles.size(); ++i)
{
sscanf(rectangles[i].c_str(), " %s %d %d", &g, &w, &h);
abcIndex[g - 'A'] += w*h;
}
int maxIndex = 0;
int intChar;
for (int i = 25; i>=0; --i)
{
if(abcIndex[i] >= maxIndex)
{
maxIndex = abcIndex[i];
intChar = i;
}
}
char retChar[256];
sprintf(retChar, "%c %d", intChar+'A', maxIndex);
return string(retChar);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment