int numJewelsInStones(string J, string S) {
     int res = 0;
     unordered_set<char> setJ(J.begin(), J.end());
     // count of unordered_set is used to find that if the key exist in the container. If yes, return true(1) 
     for (char s : S){ 
         if (setJ.count(s))
             res++;
     }
     return res;
 }
Exemplo n.º 2
0
int
PFEMElement2DBubble::update()
{
    setJ();

    if(fabs(J)<1e-15) {
        opserr<<"WARING: area is nearly zero";
        opserr<<" -- PFEMElement2DBubble::update\n";
        return -1;
    }
    setdJ();

    return 0;
}
Exemplo n.º 3
0
const char*
DgIVec2D::fromString (const char* str, char delimiter)
{
   char delimStr[2];
   delimStr[0] = delimiter;
   delimStr[1] = '\0';

   char* tmpStr = new char[strlen(str) + 1];
   strcpy(tmpStr, str);

   // Get i and j:
   char* tok;

   std::int64_t	iIn(0),
	   		jIn(0);

   try
    {
   	tok = strtok(tmpStr, delimStr);
   	iIn = dgg::util::from_string<std::int64_t>(tok);
	
   	tok = strtok(NULL, delimStr);
   	jIn = dgg::util::from_string<std::int64_t>(tok);
    }  
   catch(...)
    {
      ::report("DgIVec2D::fromString() invalid value in string " + string(tok), 
               DgBase::Fatal);
    }

   setI(iIn);
   setJ(jIn);

   std::uint64_t offset = (tok - tmpStr) + strlen(tok) + 1;
   if (offset >= strlen(str)) 
    return 0;

   return &str[offset];

} // const char* DgIVec2D::fromString