示例#1
0
文件: map.cpp 项目: mxm/vs
int main(int argc, char* argv[]) {
    //test of map function
    printmap(mymap("sample.txt"));
    std::cout << "########################" << std::endl;
    std::cout << mapserialize(mymap("sample.txt")) << std::endl;
    std::cout << "########################" << std::endl;
    printmap(mapdeserialize(mapserialize(mymap("sample.txt"))));

    return 0;
}
示例#2
0
文件: tests.cpp 项目: fanioz/ddh
void gridmap_access_test()
{
	std::cout << "gridmap_access_test..."<<std::endl;
	//const char* file = "orz700d.map";
	const char* file = "CSC2F.map";
	std::cout << "loading map..."<<file<<std::endl;
	warthog::gridmap mymap(file);
	std::cout << "map\n";
	mymap.print(std::cout);
	std::cout << "done."<<std::endl;
	return;

	for(int i=0; i < 1<<28; i++)
	{
		int x = (rand()/RAND_MAX)*mymap.width();
		int y = (rand()/RAND_MAX)*mymap.height();
		for(int nx = x-1; nx < x+2; nx++)
		{
			for(int ny = y-1; ny < y+2; ny++)
			{
				mymap.get_label(nx, ny);
			}
		}
		//std::cout << i << "\r" << std::flush;
	}
	std::cout << "gridmap_access_test..."<<std::endl;
}
示例#3
0
文件: main.cpp 项目: CCJY/coliru
int main() {
    auto hash = [](foo const& f) { return f.x; };
    std::unordered_map<foo, int, decltype(hash)> mymap(0, hash);
    
    mymap.emplace(std::make_pair(foo(42), 23));
    std::cout << mymap[foo(42)] << '\n';
}
示例#4
0
文件: mapgrid.cpp 项目: julian1/shell
void func2()
{
	ptr< IKey>	x = new Key< IMapGridAggregateRoot, IProjectionAggregateRoot> ( root, proj ); 

	std::map< ptr< IKey>, IRenderJob *,
		bool (*)( const ptr< IKey> & a, const ptr< IKey> & b )
	>		mymap( compare_keys );


	mymap.insert( std::make_pair( x, new Render( root, proj )));
}
示例#5
0
 int lengthOfLongestSubstring(string s) {
     vector<int> mymap(256,-1);
     int i,last=0,ans=0;
     for(i=0;i<s.length();i++) {
         if(mymap[s[i]]==-1 || mymap[s[i]]<last)
             ans = max(ans,i-last+1);
         else
             last = mymap[s[i]]+1;
         mymap[s[i]]=i;
     }
     return ans;
 }
    int strongPasswordChecker(string s) {
        int len = s.size(), addTarget = max(6 - len, 0), toAdd = 0, toReplace = 0;
        int lowerLetter = 1, upperLetter = 1, digit = 1;
        for (int i = 0, count = 0; i < len; ++i) {
        	if (isdigit(s[i])) digit = 0;
        	if (islower(s[i])) lowerLetter = 0;
        	if (isupper(s[i])) upperLetter = 0;

        	if (count == 0 || s[i-1] == s[i]) ++count;
        	else count = 1;
        	if (count == 3) {
        		count = 0;
        		if (toAdd < addTarget) ++toAdd;
        		else ++toReplace;
        	}
        }
        if (len <= 20) return max(addTarget + toReplace, lowerLetter + upperLetter + digit);

        int deleteTarget = len - 20, toDelete = 0;
        vector<unordered_map<int, int>> mymap(3);
        toReplace = 0;

		for (int i = 0, count = 0; i <= len; ++i) {
			if (i == len || i > 0 && s[i] != s[i-1]) {
				if (count >= 3) mymap[count % 3][count]++;
				count = 1;
			}
			else if (i == 0 || s[i-1] == s[i]) ++count;
		}
        
		for (int i = 0; i < 3; ++i) {
			int numLetter = i + 1;
			for (auto it = mymap[i].begin(); it != mymap[i].end(); ++it) {
				if (i < 2) {
					int dect = min(it->second, (deleteTarget - toDelete) / numLetter);
					toDelete += dect * numLetter;
					it->second -= dect;
					if (it->first - numLetter > 2) mymap[2][it->first - numLetter] += dect;	
				}
				toReplace += it->second * (it->first / 3);
			}
		}
		int dect = (deleteTarget - toDelete) / 3;
		toReplace -= dect, toDelete += dect * 3;
		cout << deleteTarget << " " << toDelete << " " << toReplace << endl;
		return deleteTarget + max(toReplace, lowerLetter + upperLetter + digit);
    }
示例#7
0
文件: tests.cpp 项目: fanioz/ddh
void blockmap_access_test()
{
	std::cout << "blockmap_access_test..."<<std::endl;
	const char* file = "orz700d.map";
	std::cout << "loading "<<file<<std::endl;
	warthog::blockmap mymap(file);

	for(int i=0; i < 1<<28; i++)
	{
		int x = (rand()/RAND_MAX)*mymap.width();
		int y = (rand()/RAND_MAX)*mymap.height();
		for(int nx = x-1; nx < x+2; nx++)
		{
			for(int ny = y-1; ny < y+2; ny++)
			{
				mymap.get_label(nx, ny);
			}
		}
	}
	std::cout << "/blockmap_access_test..."<<std::endl;
}