题目来源: http://community.topcoder.com/stat?c=problem_statement&pm=6041
主要是判断什么情况下会占用最小和最大的格子, 其实自己画个图很容易就找的出来.
代码如下:
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
/************** Program Begin *********************/
class Projections {
public:
vector <int> count(string front, string right) {
vector <int> res;
int mingrid;
int maxgrid;
int size = front.size();
int colsize = 0;
for (int i = 0; i < size; i++) {
if ('x' == front[i]) {
++colsize;
}
}
int rowsize = 0;
for (int i = 0; i < right.size(); i++) {
if ('x' == right[i]) {
++rowsize;
}
}
maxgrid = colsize * rowsize;
mingrid = max(colsize, rowsize);
res.push_back(mingrid);
res.push_back(maxgrid);
return res;
}
};
/************** Program End ************************/