Algorithm
Problem Statement for TheLotteryBothDivs Problem link- https://community.topcoder.com/stat?c=problem_statement&pm=11359&rd=14431 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
class TheLotteryBothDivs {
public:
double find(vector <string> goodSuffixes) {
sort(goodSuffixes.begin(), goodSuffixes.end());
goodSuffixes.resize(unique(goodSuffixes.begin(), goodSuffixes.end()) - goodSuffixes.begin());
for(int i = 0; i < goodSuffixes.size(); ++i)
for(int j = 0; j < goodSuffixes.size(); ++j)
if(i != j && goodSuffixes[j].size() >= goodSuffixes[i].size() &&
goodSuffixes[j].substr(goodSuffixes[j].size() - goodSuffixes[i].size()) == goodSuffixes[i]) {
goodSuffixes.erase(goodSuffixes.begin() + j);
i = -1;
break;
}
double ret = 0;
for(int i = 0; i < goodSuffixes.size(); ++i)
ret += pow(10, 9 - goodSuffixes[i].length()) / pow(10, 9);
return ret;
}
};
Copy The Code &
Try With Live Editor
Input
{"4"}
Output
0.1
Demonstration
TopCoder Solution SRM502-D2-500 TheLotteryBothDivs C,C++, Java, Js and Python ,SRM502-D2-500,TopCoder Solution