int main()
{
    char str[100];
    while(scanf("%s",str))
    {
        int len=strlen(str);
        int ar[100];
        for( int i=0; i<len; i++ ) ar[i]=i;
        VS v;
        string st;
        sort(ar,ar+len);
        do
        {
            for( int i=0; i<len; i++ ) st+=str[ar[i]];
            v.PB(st);
            st.clear();
        }
        while(next_permutation(ar,ar+len));
        for( int i=0; i<v.size()/len; i++ )
        {
            for( int j=i; j<v.size(); j+=7 )
                cout<<v[j]<<endl;
        }
        v.clear();
        printf("\n");
    }
    return 0;
}
예제 #2
0
 void filterDataSet(VS &data, const int scenario, const bool includeClass) {
     VI indices;
     if (scenario == 2) {
         VI sc3 = {11, 13, 19, 20, 21, 22, 23, 24, 25, 26};
         indices.insert(indices.begin(), sc3.begin(), sc3.end());
     }
     
     if (scenario >= 1) {
         VI sc2 = {2, 3, 4, 5, 6, 7, 8, 9, 10};
         indices.insert(indices.begin(), sc2.begin(), sc2.end());
     }
     
     VI sc1 = {1, 12, 14, 15, 16, 17, 18};
     indices.insert(indices.begin(), sc1.begin(), sc1.end());
     
     for (int i = 0; i < data.size(); i++) {
         string line = data[i];
         VS values = splt(line);
         string newLine;
         for (int j = 0; j < indices.size(); j++) {
             newLine.append(values[indices[j] - 1]);
             if (j < indices.size() - 1) {
                 newLine.append(",");
             }
         }
         if (includeClass) {
             newLine.append(",");
             newLine.append(values[iqCol]);
         }
         
         // store new data
         data[i] = newLine;
     }
 }
예제 #3
0
string UDFind(VS code){
  int i, j, n = code.size(); string t; Code c;
  set<string> s;               /* Mark tails already seen */
  priority_queue<Code> tails;  /* Keep track of current tails */

  sort(code.begin(), code.end(), cmpSS);
  s.clear();
  for(i = 0; i < n; i++) for(j = i+1; j < n; j++){
    if(code[i] == code[j]) return code[i];
    CHECK(code[i], code[j]);
    CHECK(code[j], code[i]);
  }
  s.clear();
  while(!tails.empty()){
    Code top = tails.top(); tails.pop();
    if(s.count(top.b)) continue;
    s.insert(top.b);
    for(j = 0; j < n; j++){
      if(top.b == code[j]) return top.a+top.b;
      CHECK2(top.b, code[j]);
      CHECK2(code[j], top.b);
    }
  }
  return "";
}
예제 #4
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;
}
예제 #5
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;
 }
예제 #6
0
VS calc( VS s ) {
    Set S;
    for ( VS::iterator it_i = s.begin(); it_i != s.end(); ++ it_i ) {
        string a = *it_i;
        string b = rotate(a);
        cout << a << ", " << b << endl;
        if ( ! is_valid(a) ) {
            if ( is_valid(b) ) {
                S.insert(b);
            }
        } else if ( ! is_valid(b) ) {
            if ( is_valid(a) ) {
                S.insert(a);
            }
        } else {
            if ( S.count(a) )
                S.insert(b);
            else if ( S.count(b) )
                S.insert(a);
            else
                S.insert(min(a, b));
        }
    }
    if ( S.size() != s.size() )
        return VS();
    VS res(S.begin(), S.end());
    return res;
}
예제 #7
0
    friend std::ostream& operator<< (std::ostream& stream, LogEntry &p) {
      stream << "func=" << p.funcName << ", ";

      VS para = p.params;
      stream << "argc=" << para.size() << ", ";
      stream << "args=[";
      for(unsigned j = 0; j < para.size() - 1; j++)
        stream << para[j] << ",";
      stream << para[para.size() - 1] << "], ";
#if GEN_DETAIL
      stream << p.getVal("S=[") << ", ";
      stream << p.getVal("E=[") << ", ";
      stream << p.getVal("D=[") << ", ";
#endif
      stream << p.getVal("R=[") << ", ";
      return stream;
    }
예제 #8
0
파일: hdu4964.cpp 프로젝트: JeraKrs/ACM
void putstring (string name, VS setid, VS setclass) {
	cout << "<" << name;

	if (setid.size() != 0) {
		cout << " id=\"" << setid[0];
		for (int i = 1; i < setid.size(); i++)
			cout << " " << setid[i];
		cout << "\"";
	}

	if (setclass.size() != 0) {
		cout << " class=\"" << setclass[0];
		for (int i = 1; i < setclass.size(); i++)
			cout << " " << setclass[i];
		cout << "\"";
	}

	cout << ">";
}
예제 #9
0
ostream& operator<<(ostream& out, const SS& s) {
	VS v;
	SS ss = s;
	while (!ss.empty()) {
		v.PB(ss.top());
		ss.pop();
	}
	for (int i = v.size() - 1; i >= 0; i--)
		out << v[i] << ' ';
	return out;
}
예제 #10
0
파일: MatArith.cpp 프로젝트: 1code/topcoder
 VVI parse(VS M) {
     VVI m;
     for (int i = 0; i < (int)M.size(); i++) {
         m.push_back(VI());
         istringstream is(M[i]);
         int n;
         while (is >> n) {
             m[i].push_back(n);
         }
     }
     return m;
 }
예제 #11
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;
 }
예제 #12
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;
                }
            }
예제 #13
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;
}
예제 #14
0
파일: learn.cpp 프로젝트: shoutgo/shoutgo
void
LEARN::learn (VS vf)
{
  INFOGO *infop;
  SGFROOT *p;
  for (int v = 0; v < vf.size (); ++v)
    {
      n_zobrist = 0;
      ___.tic ("zobrist");
      p = INOUT ().sgf2tree (vf[v]);

      // 16 种对称方式编码不一样
      for (int k = 0; k < 2; ++k)
        {
          for (int i = 0; i < 8; ++i)
            {
              infop = new INFOGO;
              g_init.swap_id8_q8 (0, i);
              p->fuseki (infop);
              for (int j = 0; j < p->sons.size (); ++j)
                {
                  visit (p->sons[j], infop, &LEARN::insert_zobrist);
                }
              g_init.swap_id8_q8 (0, i);
              infop->delfromroot ();
            }
          g_init.swap_xorand ();
        }
      /*
         // 16 种对称方式下编码都一样
         infop = new INFOGO; 
         p->fuseki(infop); 
         for (int i = 0; i<p->sons.size(); ++i){
         visit(p->sons[i], infop, &LEARN::insert_pemis); 
         infop->delfromroot(); 
         }
       */
      delete p;
      ___.toc ();
  }
  for (int v = 0; v < vf.size (); ++v)
    {
      n_pemis = 0;
      ___.tic ("pemis");
      p = INOUT ().sgf2tree (vf[v]);

      /*
         // 16 种对称方式编码不一样
         for (int k = 0; k<2; ++k){
         for (int i = 0; i<8; ++i) {
         infop = new INFOGO; 
         g_init.swap_id8_q8(0, i); 
         p->fuseki(infop); 
         for (int j = 0; j<p->sons.size(); ++j){
         visit(p->sons[j], infop, &LEARN::insert_zobrist); 
         }
         g_init.swap_id8_q8 (0, i); 
         infop->delfromroot(); 
         }
         g_init.swap_xorand(); 
         }
       */
      // 16 种对称方式下编码都一样
      infop = new INFOGO;
      p->fuseki (infop);
      for (int i = 0; i < p->sons.size (); ++i)
        {
          visit (p->sons[i], infop, &LEARN::insert_pemis);
          infop->delfromroot ();
        }
      delete p;
      ___.toc ();
    }
  INOUT ().save2txt (vf, "encodelib/filenames.txt");
}
예제 #15
0
 static Int get_maximum_number( const std::string& s ) {
   VS ret = split(s);
   // cout << endl; for ( auto x : ret ) {cout << x << endl; } cout << endl;
   return ret.size();
 }