コード例 #1
0
void MultiBlock3D::addModifiedBlocks (
        plint level,
        std::vector<MultiBlock3D*> modifiedBlocks,
        std::vector<modif::ModifT> typeOfModification,
        std::vector<std::vector<BlockAndModif> >& multiBlockCollection,
        bool includesEnvelope )
{
    PLB_PRECONDITION( modifiedBlocks.size() == typeOfModification.size() );
    // Resize vector which collects modified blocks (resize needs to be
    //   done even when no block is added, to avoid memory violations
    //   during read access to the vector).
    if ((pluint)level >= multiBlockCollection.size()) {
        multiBlockCollection.resize(level+1);
    }
    // Unless envelope is already included in the domain of application of the data
    //   processor, subscribe modified blocks for an update of the envelope.
    if (!includesEnvelope) {
        for (pluint iNewBlock=0; iNewBlock<modifiedBlocks.size(); ++iNewBlock) {
            bool alreadyAdded=false;
            // Check if the block is already in the collection.
            // Note: It may seem stupid to use a linear-complexity algorithm to
            // find existing blocks. However, it would be a mistake to store the data
            // processors in a sorted structure. Indeed, sorting pointers leads to
            // an unpredictable order (because the pointers have an unpredictable value).
            // This is a problem in parallel programs, because different threads may find a
            // different order, and the communication pattern between processes gets messed up.
            for (pluint iOriginal=0; iOriginal<multiBlockCollection[level].size(); ++iOriginal) {
                MultiBlock3D* existingBlock = multiBlockCollection[level][iOriginal].first;
                if (existingBlock == modifiedBlocks[iNewBlock]) {
                    // If the block already exists, simply update the type of modification
                    // that applies to it.
                    modif::ModifT& existingModif = multiBlockCollection[level][iOriginal].second;
                    existingModif = combine( existingModif, typeOfModification[iNewBlock] );
                    alreadyAdded = true;
                }
            }
            // If the block is not already in the structure, add it.
            if (!alreadyAdded) {
                multiBlockCollection[level].push_back (
                        BlockAndModif( modifiedBlocks[iNewBlock], typeOfModification[iNewBlock] ) );
            }
        }
    }
}
コード例 #2
0
ファイル: ImR_Client.cpp プロジェクト: milan-mpathix/ATCD
    CORBA::Object_ptr
    ImR_Client_Adapter_Impl::imr_key_to_object(TAO_Root_POA* poa,
                                               const TAO::ObjectKey &key,
                                               const char* type_id) const
    {
      TAO_ORB_Core& orb_core = poa->orb_core ();
      // Check to see if we alter the IOR.
      CORBA::Object_var imr = orb_core.implrepo_service ();

      if (CORBA::is_nil (imr.in ())
          || !imr->_stubobj ()
          || !imr->_stubobj ()->profile_in_use ())
        {
          if (TAO_debug_level > 1)
            {
              TAOLIB_DEBUG ((LM_DEBUG,
                             ACE_TEXT ("TAO_ImR_Client (%P|%t) - Missing ImR IOR, will not use the ImR\n")));
            }
          return CORBA::Object::_nil();
        }

      const TAO_MProfile& base_profiles = imr->_stubobj ()->base_profiles ();
      CORBA::String_var key_str;
      TAO::ObjectKey::encode_sequence_to_string (key_str.inout (), key);

      // if there is only one profile, no need to use IORManipulation
      if (base_profiles.profile_count() == 1)
        {
          return combine(orb_core,
                         *base_profiles.get_profile(0),
                         key_str.in(),
                         type_id);
        }

      // need to combine each profile in the ImR with the key and
      // then merge them all together into one ImR-ified ior
      ImRifyProfiles imrify (base_profiles,
                             imr->_stubobj ()->profile_in_use (),
                             orb_core,
                             key_str,
                             type_id);

      return imrify.combined_ior ();
    }
コード例 #3
0
ファイル: extr_adim.cpp プロジェクト: sunpho84/sunpho
void plot_funz_a2(const char *out_path,const char *title,const char *xlab,const char *ylab,double *X,bvec &Y,bvec &par,double (*fun)(double,double,double,double,double,double),boot &chiral_extrap_cont)
{
  //setup the plot
  grace out(out_path);
  out.plot_size(800,600);
  out.plot_title(combine("Continuum extrapolation of %s",title).c_str());
  out.axis_label(xlab,ylab);
  
  //plot the function with error
  double X_pol[100],X2_pol[100];
  bvec Y_pol(100,nboot,njack);
  for(int iens=0;iens<100;iens++)
    {
      X_pol[iens]=0.1/99*iens;
      X2_pol[iens]=X_pol[iens]*X_pol[iens];
	for(int iboot=plot_iboot=0;iboot<nboot+1;plot_iboot=iboot++)
	  Y_pol.data[iens].data[iboot]=fun(par[0][iboot],par[1][iboot],par[2][iboot],par[3][iboot],ml_phys[iboot],X_pol[iens]/hc);
    }
  out.set(1,"yellow");
  out.polygon(X2_pol,Y_pol);
  out.new_set();
  out.set(1,"red");
  out.set_line_size(2);
  out.ave_line(X2_pol,Y_pol);
  out.new_set();

  //plot the data with error
  for(int ib=0;ib<nbeta;ib++)
    {
      out.set(4,"none",set_symbol[ib],set_color[ib],"filled");
      out.set_legend(set_legend_fm[ib]);
      out.set_line_size(2);
      out.fout<<"@type xydy"<<endl;
      out.fout<<X[ib]*X[ib]<<" "<<Y.data[ib]<<endl;
      out.new_set();
    }
  
  //plot the extrapolated point with error
  out.set(4,"none","circle","indigo","filled");
  out.set_line_size(3);
  out.set_legend("Physical point");
  out.print_graph(0,chiral_extrap_cont);
  out.new_set();
}
コード例 #4
0
ファイル: main.cpp プロジェクト: tupieurods/SportProgramming
void updateTree(int index, int pos, int bl, int br, int val)
{
  if(bl == br)
  {
    tree[index].sum = val;
    tree[index].pref_sum = tree[index].suff_sum = tree[index].ans = max(0, val);
    return;
  }
  int localCenter = bl + (br - bl) / 2;
  if(pos <= localCenter)
  {
    updateTree(index * 2 + 1, pos, bl, localCenter, val);
  }
  else
  {
    updateTree(index * 2 + 2, pos, localCenter + 1, br, val);
  }
  tree[index] = combine(tree[index * 2 + 1], tree[index * 2 + 2]);
}
コード例 #5
0
void combine(int maxLength, int currentPosition, char toPrint[output_length]) {		
	if(currentPosition < maxLength) {
		for(int i = 0; i < array_size; ++i) {
			
			char newArray[output_length + 1];
			memcpy(newArray, toPrint, sizeof(toPrint));
			newArray[currentPosition] = letters[i];
			newArray[currentPosition + 1] = '\0';

			if(currentPosition + 1 == maxLength) {
				printf("%s\n", &newArray);
				counter++;
			}
			
			combine(maxLength, currentPosition + 1, newArray);
		}
		
	} 
}
コード例 #6
0
 ListNode* merge(ListNode* l, ListNode* r) {
     ListNode combine(0);
     ListNode* lastNode = &combine;
     while (l != NULL && r != NULL) {
         if (l->val < r->val) {
             lastNode->next = l;
             l = l->next;
         } else {
             lastNode->next = r;
             r = r->next;
         }
         lastNode = lastNode->next;
     }
     if (l != NULL)
         lastNode->next = l;
     else
         lastNode->next = r;
     return combine.next;
 }
コード例 #7
0
ファイル: luacompiler.c プロジェクト: zhuxiaokun/workshop
const char* luaC_complie(lua_State* L, const char* szSrcFile, const char* szDesFile)
{
	const Proto* f;
	FILE* D;
	if (luaL_loadfile(L,szSrcFile)!=0)
	{
		return lua_tostring(L, -1);
	}
	f = combine(L, 1);


	D = fopen_k(szDesFile, "wb");
	lua_lock(L);
	luaU_dump(L, f, writer, D, 0);
	lua_unlock(L);
	fclose(D);
	
	return 0;
}
コード例 #8
0
ファイル: luacompiler.c プロジェクト: zhuxiaokun/workshop
const char* luaC_complieN(lua_State* L, const char* szDesFile, int count)
{
	const Proto* f;
	FILE* D;
	if (!lua_checkstack(L, count))
	{
		return "too much files, can not compile once";
	}
	f = combine(L, count);


	D = fopen_k(szDesFile, "wb");
	lua_lock(L);
	luaU_dump(L, f, writer, D, 0);
	lua_unlock(L);
	fclose(D);

	return 0;
}
コード例 #9
0
ファイル: segtree.cpp プロジェクト: ravsa/Competitive-Coding
//Complexity: O(log n)
int query(int t, int i, int j, int l, int r) {
	if (l <=i && j <= r) {
		return seg[t];
	}
	int mid = (i + j) / 2;
	if (l <= mid) {
		if (r <= mid) {
			return query(t*2, i, mid, l, r);
		}
		else {
			int a = query(t*2, i, mid, l, r);
			int b = query(t*2 + 1,  mid + 1, j, l, r);
			return combine(a, b);
		}
	}
	else {
		return query(t*2 + 1,  mid + 1, j, l, r);
	}
}
コード例 #10
0
ファイル: native.hpp プロジェクト: grtkachenko/pasl
void parallel_for(Number lo, Number hi, const Body& body) {
#if defined(SEQUENTIAL_ELISION)
  for (Number i = lo; i < hi; i++)
    body(i);
    /* cilk_for not yet supported by mainline gcc
#elif defined(USE_CILK_RUNTIME)
  cilk_for (Number i = lo; i < hi; i++)
    body(i);
    */
#else
  struct { } output;
  using output_type = typeof(output);
  auto join = [] (output_type,output_type) { };
  auto _body = [&body] (Number i, output_type) {
    body(i);
  };
  combine(lo, hi, output, join, _body);
#endif
}
コード例 #11
0
int car_module::savedatetomysql()
{
	FILE* fpout;
	fpout=fopen("date.txt","w");
	if(fpout==NULL)
	{
		printf("can not open date.txt\n");
		return 1;
	}
	fprintf(fpout,"%d\n",mac);
	fprintf(fpout,"%d %d\n",rows,cols);
	fprintf(fpout,"%.3lf %.3lf\n",speed_rows,speed_cols);
	for(int i=0;i<rows*cols;i++)
	{
		fprintf(fpout,"%d ",combine(map_queue[i].id,map_queue[i].idle));
	}
	fclose(fpout);
	return 0;
}
コード例 #12
0
 vector<vector<int>> subsets(vector<int>& nums) {
     vector<vector<int>> result;
     vector<int> solution;
     // empty set
     result.push_back(solution);
     
     if (nums.size() <= 0) {
         return result;
     }
     
     sort(nums.begin(), nums.end());
     
     for (int sub_size = 1; sub_size <= nums.size(); sub_size++) {
         // using backtracking, get all subset, which size is sub_size
         vector<vector<int>> subs = combine(nums, sub_size);
         // extend result: put sub in subs to result
         result.insert(result.end(), subs.begin(), subs.end());
     }
     return result;
 }
コード例 #13
0
ファイル: inint_TLE.cpp プロジェクト: alxsoares/OI
Matrix merge(const Matrix &A, const Matrix &B, int s, bool can_nine) {
	Matrix res;
	for ( int i = 0; i <= 9; i ++ )
		for ( int j = 0; j <= 9; j ++ ) {
			Info I1 = A.ele[i][j];
			I1.val ++;
			for ( int x = 1; x <= 9; x ++ )
				if ( (s & (1 << x)) || x == j || (can_nine && x == 9) ) {
					int t = x + j;
					if ( t >= 10 ) {
						t -= 10;
						for ( int k = 0; k <= 9; k ++ ) {
							Info I2 = B.ele[t][k];
							res.ele[i][k].update(combine(I1, I2));
						}
					}
				}
		}
	return res;
}
コード例 #14
0
ファイル: mpatch.c プロジェクト: Distrotech/mercurial
/* recursively generate a patch of all bins between start and end */
static struct flist *fold(PyObject *bins, Py_ssize_t start, Py_ssize_t end)
{
	Py_ssize_t len, blen;
	const char *buffer;

	if (start + 1 == end) {
		/* trivial case, output a decoded list */
		PyObject *tmp = PyList_GetItem(bins, start);
		if (!tmp)
			return NULL;
		if (PyObject_AsCharBuffer(tmp, &buffer, &blen))
			return NULL;
		return decode(buffer, blen);
	}

	/* divide and conquer, memory management is elsewhere */
	len = (end - start) / 2;
	return combine(fold(bins, start, start + len),
		       fold(bins, start + len, end));
}
コード例 #15
0
ファイル: bank_utils.c プロジェクト: wojtex/studia-so-archeo
long long int get_money_of_company(double_queue_t *q, int idx, int id, long source) {
  void *query, *response;
  size_t qlen, response_size;
  int exit_on_signal = 0;
  combine(&query, &qlen, "%c %i %i", ACT_BANK_GET_SALDO, idx, id);
  if(double_queue_query(q, query, qlen, &response, &response_size, &exit_on_signal, source, bank_ip) != 0) {
    error("Error connecting to bank.");
    free(query);
    return -1;
  }
  long long int saldo = -1;
  free(query);
  if(match(response, response_size, "@c %ll", ACT_OK, &saldo) != 0) {
    error("Expected OK message - something went wrong.");
    free(response);
    return -1;
  }
  free(response);
  return saldo;
}
コード例 #16
0
ファイル: UnionSelector.cpp プロジェクト: 4og/avango
/* virtual */ void
av::tools::UnionSelector::evaluate()
{
  av::tools::Selector::evaluate();

  if (TargetSet1.isEmpty())
  {
    if (!TargetSet2.isEmpty())
      SelectedTargets.setValue(TargetSet2.getValue());
    else if (!SelectedTargets.isEmpty())
      SelectedTargets.clear();
  }
  else if (TargetSet2.isEmpty())
    SelectedTargets.setValue(TargetSet1.getValue());
  else
  {
    const MFTargetHolder::ContainerType &set1 = TargetSet1.getValue();
    const MFTargetHolder::ContainerType &set2 = TargetSet2.getValue();
    MFTargetHolder::ContainerType selected_targets;

    for (MFTargetHolder::ContainerType::const_iterator holder1 = set1.begin();
         holder1 != set1.end(); ++holder1)
    {
      const SFContainer::ValueType &target = (*holder1)->Target.getValue();
      MFTargetHolder::ContainerType::const_iterator holder2 = find(set2, target);
      if (holder2 == set2.end())
        selected_targets.push_back(*holder1);
      else
        selected_targets.push_back(combine(*holder1, *holder2));
    }

    for (MFTargetHolder::ContainerType::const_iterator holder2 = set2.begin();
         holder2 != set2.end(); ++holder2)
    {
      if (!hasTarget(set1, (*holder2)->Target.getValue()))
        selected_targets.push_back(*holder2);
    }

    SelectedTargets.setValue(selected_targets);
  }
}
コード例 #17
0
ファイル: luac.c プロジェクト: tearsofphoenix/VeritasIDE
int lua_dumpSourceCode(lua_State* L, const char *sourceCode, const char* outputPath)
{
    if (luaL_loadstring(L, sourceCode) != LUA_OK)
    {
        fatal(lua_tostring(L,-1));
    }
    
    const Proto* f = combine(L, 1);
    if (listing)
    {
        luaU_print(f,listing>1);
    }
    
    if (dumping)
    {
        FILE* D = fopen(outputPath, "wb");
        
        if (D==NULL)
        {
            printf(" error to open file!\n");
        }
        
        lua_lock(L);
        
        luaU_dump(L,f,writer,D,stripping);
        
        lua_unlock(L);
        
        if (ferror(D))
        {
            printf("error in write!\n");
        }
        
        if (fclose(D))
        {
            printf("error in close!\n");
        }
    }
    
    return 0;
}
コード例 #18
0
ファイル: item.cpp プロジェクト: gustavsen/keeperrl
string Item::getModifiers(bool shorten) const {
  string artStr;
  if (attributes->artifactName) {
    artStr = *attributes->artifactName;
    if (!shorten)
      artStr = " named " + artStr;
  }
  EnumSet<ModifierType> printMod;
  switch (getClass()) {
    case ItemClass::WEAPON:
      printMod.insert(ModifierType::ACCURACY);
      printMod.insert(ModifierType::DAMAGE);
      break;
    case ItemClass::ARMOR:
      printMod.insert(ModifierType::DEFENSE);
      break;
    case ItemClass::RANGED_WEAPON:
    case ItemClass::AMMO:
      printMod.insert(ModifierType::FIRED_ACCURACY);
      break;
    default: break;
  }
  if (!shorten)
    for (auto mod : ENUM_ALL(ModifierType))
      if (attributes->modifiers[mod] != 0)
        printMod.insert(mod);
  vector<string> attrStrings;
  for (auto mod : printMod)
    attrStrings.push_back(withSign(attributes->modifiers[mod]) +
        (shorten ? "" : " " + Creature::getModifierName(mod)));
  if (!shorten)
    for (auto attr : ENUM_ALL(AttrType))
      if (attributes->attrs[attr] != 0)
        attrStrings.push_back(withSign(attributes->attrs[attr]) + " " + Creature::getAttrName(attr));
  string attrString = combine(attrStrings, true);
  if (!attrString.empty())
    attrString = " (" + attrString + ")";
  if (attributes->uses > -1 && attributes->displayUses) 
    attrString += " (" + toString(attributes->uses) + " uses left)";
  return artStr + attrString;
}
コード例 #19
0
ファイル: CH11PR3.C プロジェクト: somit/Cbookproblems
struct lledge * kminstree ( struct lledge *root, int n )
{
	struct lledge *temp = NULL ;
	struct lledge *p, *q ;
	int noofedges = 0 ;
	int i, p1, p2 ;

	for ( i = 0 ; i < n ; i++ )
		stree[i] = i ;
	for ( i = 0 ; i < n ; i++ )
		count[i] = 0 ;

	while ( ( noofedges < ( n - 1 ) ) && ( root != NULL ) )
	{
		p = root ;

		root = root -> next ;

		p1 = getrval ( p -> v1 ) ;
		p2 = getrval ( p -> v2 ) ;

		if ( p1 != p2 )
		{
			combine ( p -> v1, p -> v2 ) ;
			noofedges++ ;
			mincost += p -> cost ;
			if ( temp == NULL )
			{
				temp = p ;
				q = temp ;
			}
			else
			{
				q -> next = p ;
				q = q -> next ;
			}
			q -> next = NULL ;
		}
	}
	return temp ;
}
コード例 #20
0
int main()
{
    char s1[MAXL + 6];
    char s2[MAXL + 6];
    int t1, t2;
    init();
    initNode(0);
    nodeNumber = 1;
    wordNumber = 0;
    memset(color, 0, sizeof(color));
    while(~scanf("%s%s", s1, s2))
    {
        t1 = addWord(0, s1);
        t2 = addWord(0, s2);
        ++ color[t1];
        ++ color[t2];
        combine(t1, t2);
    }
    bool connectivity = true;
    int oddNumber = 0;
    for(int i=0;i<wordNumber;++i)
    {
        if(find(i) != find(0))
        {
            connectivity = false;
        }
        if(color[i] & 1)
        {
            ++ oddNumber;
        }
    }
    if(!connectivity || oddNumber > 2)
    {
        printf("Impossible\n");
    }
    else
    {
        printf("Possible\n");
    }
    return 0;
}
コード例 #21
0
ファイル: read-command.c プロジェクト: mfaywu/cs111
void processOperator(int operator)
{
	if (operatorStack == NULL)
	{
		push(operator, NULL);
	}
	else
	{
		if (precedence(operator) > precedence(peekOperator()))
		{
			push(operator, NULL);
		}
		else
		{
			while (precedence(peekOperator()) != 0 && precedence(operator) <= precedence(peekOperator()))
			{
				int topOper = peekOperator();
				if(topOper == 1) 
				{
					command_t topCommand = peekCommand();
					pop(false);
					command_t newCommand = makeSubshell(topCommand);
				}
				if(topOper != 1)
				{
					int tempOper = peekOperator();
					pop(true);
					command_t secondCommand = peekCommand();
					pop(false);
					command_t firstCommand = peekCommand();
					pop(false);
					command_t newCommand = combine(firstCommand, secondCommand, tempOper);
					push(-1, newCommand);
				}
				if (operatorStack == NULL)
					break;
			}
			push(operator, NULL);
		}
	}
}
コード例 #22
0
ファイル: 1380.cpp プロジェクト: wulangbnu/ACM
void zhuliu(int root)
{
	int i, j;
	for(i = 1; i <= n; ++i) {
		id[i] = i;
		if(i == root)	continue;
		mincost[i] = INF;
		for(j = 1; j <= n; ++j)
			if(i != j && e[j][i] < mincost[i]) {
				mincost[i] = e[j][i];
				pre[i] = j;
			}

	}
	while(findcircle(root))
		combine(root);
	for(i = 1; i <= n; ++i) {
		if(i != root && id[i] == i)
			ans += mincost[i];
	}
}
コード例 #23
0
ファイル: luac.c プロジェクト: Akagi201/learning-lua
int main(int argc, const char* argv[])
{
 Proto** P,*tf;
 int i=doargs(argc,argv);
 argc-=i; argv+=i;
 if (argc<=0) usage("no input files given",NULL);
 L=lua_open(0);
 P=luaM_newvector(L,argc,Proto*);
 for (i=0; i<argc; i++)
  P[i]=load(IS("-")? NULL : argv[i]);
 tf=combine(P,argc);
 if (dumping) luaU_optchunk(tf);
 if (listing) luaU_printchunk(tf);
 if (testing) luaU_testchunk(tf);
 if (dumping)
 {
  if (stripping) strip(tf);
  luaU_dumpchunk(tf,efopen(output,"wb"));
 }
 return 0;
}
コード例 #24
0
ファイル: combination-sum.cpp プロジェクト: mkubilayk/coding
    void combine(LLI &results, LI &set, LI &candidates, int k, int target) {
        int sum = 0;
        for (int x : set)
            sum += x;

        if (sum == target) {
            LI sorted = set;
            sort(sorted.begin(), sorted.end());
            results.push_back(sorted);
            return;
        }

        if (target < sum)
            return;

        for (int i = k; i < candidates.size(); ++i) {
            set.push_back(candidates[i]);
            combine(results, set, candidates, i, target);
            set.pop_back();
        }
    }
コード例 #25
0
ファイル: Word_Break_2.cpp プロジェクト: HevaWu/leetcode
 vector<string> wordBreak(string s, unordered_set<string>& wordDict) {
     if(mymap.count(s)) return mymap[s];
     
     vector<string> ret;
     if(wordDict.count(s)){
         ret.push_back(s);
     }
     
     for(int i = 1; i < s.size(); ++i){
     	//backtracking
         string word = s.substr(i);
         if(wordDict.count(word)){
             string rem = s.substr(0, i);
             vector<string> pre = combine(word, wordBreak(rem, wordDict));
             ret.insert(ret.end(), pre.begin(), pre.end());
         }
     }
     
     mymap[s] = ret;
     return ret;
 }
コード例 #26
0
void NFAGenerator::getNFA(){

	if (languageFile==NULL)
	{
		cout << "File Not Opened" << endl;
		return;
	}

	string lineStr;
	char line[1000];
	while( fgets(line,1000,languageFile) != NULL ){
		line[1000];
		string lineStr(line);
		unsigned  pos = lineStr.find("\n");
		lineStr = lineStr.substr (0,pos);
		parseLine(lineStr);
		//cout<< lineStr;
	}

	combine();
	
}
コード例 #27
0
ファイル: Font.cpp プロジェクト: PKEuS/SFML
const Glyph& Font::getGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, float outlineThickness) const
{
    // Get the page corresponding to the character size
    GlyphTable& glyphs = m_pages[characterSize].glyphs;

    // Build the key by combining the glyph index (based on code point), bold flag, and outline thickness
    Uint64 key = combine(outlineThickness, bold, FT_Get_Char_Index(static_cast<FT_Face>(m_face), codePoint));

    // Search the glyph into the cache
    GlyphTable::const_iterator it = glyphs.find(key);
    if (it != glyphs.end())
    {
        // Found: just return it
        return it->second;
    }
    else
    {
        // Not found: we have to load it
        Glyph glyph = loadGlyph(codePoint, characterSize, bold, outlineThickness);
        return glyphs.emplace(key, glyph).first->second;
    }
}
コード例 #28
0
ファイル: source.c プロジェクト: nevergiveupyang1989/leetcode
void combine(int n, int k) {
    int i;
    int j;

    for(i=n; i>=k; i--)
    {
	    a[k] = i;
	    if(k>1)
	    {
		combine(n-1, k-1); 
	    }
	    else
	    {
		cnt++;
		for(j=a[0]; j>0; j--)
		{
			printf("%d", a[j]);
		}
		printf("\n");		
	    }
    }
}
コード例 #29
0
ファイル: 组合数.cpp プロジェクト: springer126/C-World
void combine(int n,int k)
{
	if(n<1 || k<1)
		return;
	if(k>n)
		return;

	for (int i=n;i>=k;i--)
	{
		a[k-1] = i;
		if(k>1)
			combine(i-1,k-1);
		else
		{
			for (int j=0;j<3;j++)
			{
				printf("%d ",a[j]);
			}
			printf("\n");
		}
	}
}
コード例 #30
0
ファイル: huffman.c プロジェクト: deenaariff/HuffmanEncoding
int main(int argc, const char * argv[]) {
    FILE *fp;
    int *freq = calloc(256, sizeof(int));
    struct heap* huffman = malloc(sizeof(struct heap*));
    int val = 0;

    // Open and Read File
    fp = fopen("test.rtf", "r");
    if (fp == NULL) {
        printf("File not Found\n");
        return 0;
    }
    while ((val = fgetc(fp)) != EOF)
        freq[val]++;
    printf("Read file");

    // Put frequencies into freq array
    int i = 0;
    for(i = 0; i < 254; i++) {
        Node* tmp = malloc(sizeof(Node*));
        tmp -> val = freq[i];
        insert(huffman, tmp);
    }

    // Set constant min-heap min
    Node* eof;
    eof -> val = -1;
    insert(huffman, eof);

    while (huffman -> count != 1) {
        Node* tmp1 = pop(huffman);
        Node* tmp2 = pop(huffman);
        tmp2 = combine(tmp1, tmp2);
        insert(huffman, tmp2);
    }

    printf("Complete!");
    return 0;
}