예제 #1
0
 static bool update( VS& v ) {
   int n = v.size();
   if ( n <= 1 ) {
     return false;
   }
   if ( n == 2 ) {
     if ( check(v[0], v[1]) ) {
       VS nv;
       nv.push_back(v[0] + v[1]);
       v = nv;
       return true;
     }
     return false;
   }
   string tmp = "";
   for ( auto i = 0; i + 1 < n; ++ i ) {
     tmp += v[i];
     if ( check(tmp, v[i + 1]) ) {
       VS nv;
       nv.push_back(tmp);
       for ( int j = i + 1; j < n; ++ j ) {
         nv.push_back(v[j]);
       }
       v = nv;
       return true;
     }
   }
   return false;
 }
예제 #2
0
void Mesh::addQuad(float width, float height) {
  int indexOffset = positions.size();
  float x = width / 2.0f;
  float y = height / 2.0f;

  VVec4 quad;
  // C++11      { glm::vec3(-x, -y, 0), glm::vec3(x, -y, 0), glm::vec3(x, y, 0), glm::vec3(-x, y, 0),  });
  quad.push_back(glm::vec4(-x, -y, 0, 1));
  quad.push_back(glm::vec4(x, -y, 0, 1));
  quad.push_back(glm::vec4(x, y, 0, 1));
  quad.push_back(glm::vec4(-x, y, 0, 1));

  // Positions are transformed
  add_all_transformed(model.top(), positions, quad);
  if (normals.size()) {
    // normals are transformed with only the rotation, not the translation
    model.push().untranslate();
    add_all_transformed(model.top(), normals, quad);
    model.pop();
  }

  // indices are copied and incremented
  VS quadIndices;
  // C++11 VS( { 0, 1, 2, 0, 2, 3 } );
  quadIndices.push_back(0);
  quadIndices.push_back(1);
  quadIndices.push_back(2);
  quadIndices.push_back(0);
  quadIndices.push_back(2);
  quadIndices.push_back(3);
  add_all_incremented(indexOffset, indices, quadIndices);

  fillColors();
  fillNormals();
}
예제 #3
0
 VS splt(std::string s, char c = ',') {
     VS all;
     int p = 0, np;
     while (np = (int)s.find(c, p), np >= 0) {
         if (np != p)
             all.push_back(s.substr(p, np - p));
         else
             all.push_back("");
         
         p = np + 1;
     }
     if (p < s.size())
         all.push_back(s.substr(p));
     return all;
 }
예제 #4
0
VS replyVector() {
    VS ret;
    return ret;
    ret.push_back("titi");
    ret.push_back("tutu");
    return ret;
}
예제 #5
0
void main()
{
	string strWord,strKey;int i;MSVS msvsDictionary;
	while(cin>>strWord)
	{
		if(strWord.compare("XXXXXX")==0)break;
		strKey=strWord;sort(strKey.begin(),strKey.end());
		if(msvsDictionary.find(strKey)==msvsDictionary.end())
		{
			VS vsList;vsList.push_back(strWord);
			msvsDictionary.insert(MSVS::value_type(strKey,vsList));
		}
		else msvsDictionary[strKey].push_back(strWord);
	}
	while(cin>>strKey)
	{
		if(strKey.compare("XXXXXX")==0)break;
		sort(strKey.begin(),strKey.end());
		if(msvsDictionary.find(strKey)==msvsDictionary.end())cout<<"NOT A VALID WORD"<<endl;
		else
		{
			sort(msvsDictionary[strKey].begin(),msvsDictionary[strKey].end());
			for(i=0;i<msvsDictionary[strKey].size();i++)
				cout<<msvsDictionary[strKey][i]<<endl;
		}
		cout<<"******"<<endl;
	}
}
예제 #6
0
파일: C.cpp 프로젝트: delta4d/AlgoSolution
int main() {
	int m, n;
	int i, j, k;
	int max_subfile, max_file;
	string s, x;
	//freopen("f:\\in.txt", "r", stdin);
	while (cin >> s) {
		flist.clear();
		for (i=3; s[i]; ++i) {
			if (s[i] == '\\') flist.push_back(s.substr(0, i));
		}
		n = flist.size();
		for (i=0; i!=n; ++i) {
			if (fc.find(flist[i]) == fc.end()) {
				for (j=0; j!=i; ++j) {
					if (subfile.find(flist[j]) == subfile.end()) subfile.insert(make_pair(flist[j], 1));
					else ++subfile[flist[j]];
				}
				fc.insert(flist[i]);
			}
			if (file.find(flist[i]) == file.end()) file.insert(make_pair(flist[i], 1));
			else ++file[flist[i]];
		}
	}
	max_subfile = 0, max_file = 0;
	for (MSII it=subfile.begin(); it!=subfile.end(); ++it) max_subfile = max(max_subfile, it->second);
	for (MSII it=file.begin(); it!=file.end(); ++it) max_file = max(max_file, it->second);
	printf("%d %d\n", max_subfile, max_file);
	return 0;
}
예제 #7
0
 VS convert( string s ) {
     VS res;
     ISS iss(s);
     string word;
     while ( iss >> word )
         res.push_back(word);
     return res;
 }
예제 #8
0
VS split( string s, string c )
{
  VS ret;
  for( int i=0, n; i <= s.length(); i=n+1 ){

    n = s.find_first_of( c, i );
    if( n == string::npos ) n = s.length();
    string tmp = s.substr( i, n-i );
    ret.push_back(tmp);
  }
  return ret;
}
예제 #9
0
MSM replyMap2() {
    MSM ret;
    VS v;

    return ret;
    v.push_back("titi");
    v.push_back("tutu");

    ret["titi"] = v;
    ret["tutu"] = v;
    return ret;
}
예제 #10
0
int main(){
  int i, n; char buff[MAXL]; VS code;

  while(scanf("%d", &n) == 1){
    code.clear();
    for(i = 0; i < n; i++){
      scanf(" %s", buff);
      code.push_back(buff);
    }
    printf("[%s]\n", UDFind(code).c_str());
  }
  return 0;
}
예제 #11
0
/*Get the parameter starting with key in record a*/
VS LogEntry::_getPara(const string &a)
{
  int start, end, i;
  start= a.find('(');
  start++;
  i = start;
  end=a.find(')');

  this->strPara = a.substr(start, end-start);

  VS result;

  while(i < end) {
    if(a[i] == ',') {
      result.push_back(a.substr(start, i-start));
      start = i + 1;
    }
    i++;
  }
  result.push_back(a.substr(start, i-start));

  return result;
}
예제 #12
0
 static VS split( const std::string& s ) {
   VS res;
   string rs = s;
   std::reverse(begin(rs), end(rs));
   string tmp;
   for ( auto c : rs ) {
     tmp += c;
     if ( c != '0' ) {
       std::reverse(begin(tmp), end(tmp));
       res.push_back(tmp);
       tmp = "";
     }
   }
   if ( tmp != "" ) {
     std::reverse(begin(tmp), end(tmp));
     res.push_back(tmp);
     tmp = "";
   }
   std::reverse(begin(res), end(res));
   while ( res.size() >= 2 ) {
     bool flag = false;
     if ( res[0].size() == res[1].size() && res[0] < res[1] ) {
       flag = true;
     } else if ( res[0].size() < res[1].size() ) {
       flag = true;
     }
     if ( flag ) {
       // cout << "res = " << res[0] << " / " << res[1] << endl;
       res[0] += res[1];
       res.erase(begin(res) + 1);
     } else {
       break;
     }
   }
   while ( update(res) );
   return res;
 }
예제 #13
0
void CalcMatrix(const vector<CompositeData> data, VVI & RM, VVI & DM,
		VS & deci_val) {
	if (data.size() == 0 ) {
		cerr << "Input data is empty!" << endl;
		exit(-1);
	}
	unsigned int i, j;
	//Calc Relation Matrix
	RM.clear();
	VI vbTmp(data.size(), 0);
	RM.insert(RM.begin(), data.size(), vbTmp);
	for (i = 0; i < data.size(); ++i) {
		for (j = 0; j < data.size(); ++j) {
			if (data[i] == data[j])
				RM[i][j] = 1;
		}
		RM[i][i] = 1;
	}

	//Calc Relation Matrix
	STR2VI_MAP DMap;
	STR2VI_MAP::iterator it;
	for (i = 0; i < data.size(); ++i) {
		it = DMap.find(data[i].d);
		if (it == DMap.end()) {
			VI tmp;
			tmp.push_back(i);
			DMap.insert(STR2VI_MAP::value_type(data[i].d, tmp));
		} else {
			((*it).second).push_back(i);
		}
	}

	//DM: n * d
	//DMap.size() = d
	DM.clear();
	VI viTmp(DMap.size(), 0);
	DM.insert(DM.begin(), data.size(), viTmp);

//	cout << DM.size() << "\t" << DM[0].size() << endl;

	for (i = 0, it = DMap.begin(); it != DMap.end(); ++it, ++i) {
		deci_val.push_back((*it).first);
		for (j = 0; j < (*it).second.size(); ++j) {
			DM[(*it).second[j]][i] = 1;
		}
	}
	DMap.clear();
}
예제 #14
0
파일: MatArith.cpp 프로젝트: 1code/topcoder
 VS print(VVI & m) {
     VS M;
     for (int i = 0; i < (int)m.size(); i++) {
         M.push_back("");
         for (int j = 0; j < (int)m[i].size(); j++) {
             ostringstream os;
             os << m[i][j];
             if (j == 0) M[i] += os.str();
             else M[i] += (" " + os.str()); 
         }
     }
     //for (int i = 0; i < (int)M.size(); i++)
         //cout << M[i] << endl;
     return M;
 }
예제 #15
0
vector <string> token( string str,string deli )
{
    char * cstr, *p,*deli_c;
    deli_c = new char [deli.size()+1];
    cstr = new char [str.size()+1];
    strcpy(deli_c,deli.c_str());
    strcpy (cstr, str.c_str());
    VS vec;
    p=strtok(cstr,deli_c);
    while(p!=NULL)
    {
        vec.push_back( string(p));
        p=strtok(NULL,deli_c);
    }
    delete[] cstr;
    return vec;
}
예제 #16
0
파일: common.cpp 프로젝트: Grabot/gmap
VS SplitNotNull(const string& ss, const string& c)
{
	string s = ss + c;
	VS result;
	string tec = "";
	for (int i = 0; i < (int)s.length(); i++)
	{
		if (c.find(s[i]) != string::npos)
		{
			if ((int)tec.length() > 0) result.push_back(tec);
			tec = "";
		}
		else tec += s[i];
	}

	return result;
}
	    vector <string> generateTable(vector <string> results, vector <int> sort, string order) {
		
		map<string, dude> memo;
		srt = sort;
		ord = order;
		n = (int)order.size();
		
		for (vector<string>::const_iterator i=results.begin(); i!=results.end(); ++i) {
			VS tmp = tokenize<string>(*i);
			dude &a = memo[tmp[0]];
			a.name = tmp[0];
			// "NAME METRIC COUNT SCORE"
			if (atoi(tmp[2].c_str()) > a.count[atoi(tmp[1].c_str())]) {
				a.count[atoi(tmp[1].c_str())] = atoi(tmp[2].c_str());
				a.score[atoi(tmp[1].c_str())] = atoi(tmp[3].c_str());
			}
		}
		vector<dude> tmprry;
		for (map<string, dude>::const_iterator i=memo.begin(); i!=memo.end(); ++i)
			tmprry.push_back(i->second);
		
		for (vector<dude>::iterator i=tmprry.begin(); i!=tmprry.end(); ++i)
			for (vector<dude>::iterator j=i+1; j!=tmprry.end(); ++j)
				if (*j < *i) {
					dude a = *i; *i = *j; *j = a;
				}
			
		VS sol;
		for (vector<dude>::const_iterator i=tmprry.begin(); i!=tmprry.end(); ++i) {
			string t = i->name;
			for (int j=1; j<=n; ++j) {
				if (abs(i->score[j]) < INFTY)
					t += ' '+to_str<int>(i->score[j]);
				else t += " -";
			}
			sol.push_back(t);
		}
		return sol;	
    }
예제 #18
0
파일: 10511.cpp 프로젝트: m4b3l/algorithm
int main() {
	ios_base::sync_with_stdio(false);
	int T;
	cin >> T;
	string s;
	getline(cin, s);
	getline(cin, s);
	while(T--){
		bool f;
		do{
			f = getline(cin, s);
			V.push_back(s);
		}while(s.size() > 0 && f);
//		for(int i=0; i<4; i++){
//			getline(cin, s);
//			V.push_back(s);
//		}
//		
		map<string, int> SS;
		map<string, int> SS1;
		map<int, string> RE;
		VS name(V.size());
		VS party(V.size());
		vector<VS> club(V.size());
		
		int k = 1;
		int c = 0;
		
		for(int i=0; i<V.size(); i++){
			int p1;
			for(p1=0; p1<V[i].size(); p1++){
				if(V[i][p1] == ' ') break;
				name[i] += V[i][p1];
			}
			for(p1 = p1+1; p1 < V[i].size(); p1++){
				if(V[i][p1] == ' ') break;
				party[i] += V[i][p1];
			}
			while(p1 < V[i].size()){
				string temp;
				for(p1 = p1+1; p1 < V[i].size(); p1++){
					if(V[i][p1] == ' ') break;
					temp += V[i][p1];
				}
				if(!SS1.count(temp)){
					SS1[temp] = c;
					RE[c] = temp;
					c++;
				}
				club[i].push_back(temp);
			}
			if(!SS.count(party[i]))
				SS[party[i]] = k++;
		}
		MaxFlowDinic MD( 80000 );
		
		map<string, int>::iterator it;
		for(it = SS.begin(); it != SS.end(); it++){
			MD.add_edge(0, it->second, SS.size()%2==0? SS.size()/2-1:SS.size()/2);
		}
		
		k = SS.size() + 1;
		for(int i=0; i<V.size(); i++, k++){
			int p = SS[party[i]];
			MD.add_edge(p, k, 1);
			for(int j=0; j<club[i].size(); j++){
				MD.add_edge(k, SS1[club[i][j]] + SS.size() + 1 + V.size(), 1);
			}
		}
		
		for(it = SS1.begin(); it != SS1.end(); it++){
			MD.add_edge( (it->second) + SS.size() + 1 + V.size(), 
					SS1.size() + SS.size() + 1 + V.size(), 1);
		}
		
		int res = MD.dinic(0, SS1.size() + SS.size() + 1 + V.size());
		if(res < SS1.size()){
			cout << "Impossible." << endl;
		}else{
			for(int i=0; i<MD.edges.size(); i+=2){
				if(MD.edges[i].v == SS1.size() + SS.size() + 1 + V.size()) continue;
				if(MD.edges[i].u < SS.size() + 1) continue;
				if(MD.edges[i].flow <= 0) continue;
				int u = MD.edges[i].u;
				int v = MD.edges[i].v;
				u -= (SS.size() + 1);
				v -= (SS.size() + 1 + V.size());
				cout << name[u] << " " << RE[v] << endl;
			}
		}
		if(T > 0){
			cout << endl;
		}
	}
    return 0;
}
예제 #19
0
            void generateTestData(const int scenario, const int subset) {
                size_t subset_total = dataSamples.size() / subsetsNum;
                int train_start_index = subset * (int)subset_total;
                int test_start_index = train_start_index + subset_total * 0.66;
                int end_index = train_start_index + (int)subset_total;
                if (end_index > dataSamples.size()) {
                    end_index = (int)dataSamples.size();
                }
                
                //
                // prepare train data
                //
                DTrain.clear();
                double mean = 0;
                int countIq = 0;
                for (int i = train_start_index; i < test_start_index; i++) {
                    VS rows = dataSamples[i];
                    for (int r = 0; r < rows.size(); r++) {
                        string line = rows[r];
                        VS values = splt(line);
                        double iq = atof(values[iqCol].c_str());
                        
                        if (scenario > 0) {
                            DTrain.push_back(line);
                        } else if (iq > 0) {
                            // add only line with IQ set for 1 scenario
                            DTrain.push_back(line);
                        }
                        
                        if (iq > 0) {
                            mean += iq;
                            countIq++;
                        }
                    }
                }
//                filterDataSet(DTrain, scenario, true);
                
                //
                // prepare test data
                //
                DTest.clear();
                groundTruth.clear();
                for (int i = test_start_index; i < end_index; i++) {
                    VS rows = dataSamples[i];
                    for (int r = 0; r < rows.size(); r++) {
                        string line = rows[r];
                        VS values = splt(line);
                        double iq = atof(values[iqCol].c_str());
                        if (iq > 0) {
                            groundTruth.push_back(iq);
                            // add only line with IQ set for 1 scenario
                            DTest.push_back(line);
                        } else if (scenario > 0) {
                            DTest.push_back(line);
                        }
                    }
                }
//                filterDataSet(DTest, scenario, false);
                
                //
                // calculate sse0
                //
                mean /= countIq;
                sse0 = 0;
                for (const double &iq : groundTruth) {
                    double e = mean - iq;
                    sse0 += e * e;
                }
            }