/* ------------------------------------------------------------------------------------- // _sdyALPushMakeFree - kick a sound to make room for a new one //------------------------------------------------------------------------------------- */ sdyBool SDYAPI _sdyALPushMakeFree(SDY_SOUND* pSoundPush) { CONT_ITEM* i; SDY_SOUND* pSound; if(ccount(g_cAudLines) >= g_wMaxAudLines) { /* find a sound to kick out */ i = cfirst(g_cAudLines); while(i) { pSound = (SDY_SOUND*)cidata(i); i = cinext(i); if(pSound->nPriority <= pSoundPush->nPriority) { //_sdyALPop(pSound); sdyALStop(pSound); return sdyTrue; } } return sdyFalse; /* not playable at the moment */ } return sdyTrue; }
int main (int argc, const char * argv[]) { char *str="hellobrishtiiloveulol"; printf("counted character = %d \n", ccount(str,'m')); return 0; }
strsize_t String::ccount(const char *clist) const { if(!str) return 0; return ccount(str->text, clist); }
/* return number of values in n'th occurence of parameter name */ int countnparval (int n, char *name) { int i; if (xargc == 1) return 0; if (!tabled) getparinit(); i = getparindex(n,name); if (i>=0) return ccount(',',argtbl[i].asciival) + 1; else return 0; }
int main(){ const int N = 26; std::string a; getline(std::cin, a); std::string b; getline(std::cin, b); std::string c; getline(std::cin, c); std::vector<size_t> acount(N, 0); for(size_t p = 0; p < a.size(); p++){++acount[a[p] - 'a'];} std::vector<size_t> bcount(N, 0); for(size_t p = 0; p < b.size(); p++){++bcount[b[p] - 'a'];} std::vector<size_t> ccount(N, 0); for(size_t p = 0; p < c.size(); p++){++ccount[c[p] - 'a'];} long maxB(a.size()); for(size_t p = 0; p < N; p++){if(bcount[p] > 0 && (acount[p] / bcount[p]) < maxB){maxB = (acount[p] / bcount[p]);}} long maxSum(maxB), optB(maxB), optC(0); for(size_t b = 0; b <= maxB; b++){ size_t candC(a.size()); for(size_t p = 0; p < N; p++){if(ccount[p] > 0 && ((acount[p] - b * bcount[p])/ ccount[p]) < candC){candC = (acount[p] - b * bcount[p])/ccount[p];}} if(b + candC > maxSum){maxSum = b + candC; optB = b; optC = candC;} } for(int p = 0; p < optB; p++){std::cout << b;} for(int p = 0; p < optC; p++){std::cout << c;} for(int p = 0; p < N; p++){ size_t rem = acount[p] - optB * bcount[p] - optC * ccount[p]; while(rem--){std::cout << char('a' + p);} } std::cout << std::endl; return 0; }
Float evaluate_sequences(vector<vector<int> > &goldS, vector<vector<int> > &predicted, vector<string> &LIS , int num_labels, int verbose, ofstream &out){ int numtag,numctag,numbtag; numtag=numctag=numbtag=0; int num_class = ( num_labels / 2 ) + 1; vector<int> ccount(num_class,0),pcount(num_class,0),ncorrect(num_class,0), nleft(num_class,0),nright(num_class,0), nbcorrect(num_class,0),nbleft(num_class,0),nbright(num_class,0); int match,bmatch; match=bmatch=0; int num_seq = goldS.size(); for (int i = 0; i < num_seq ; ++i){ // For each sequence unsigned int N = goldS[i].size(); if ( N != predicted[i].size() ) { cerr << "Unmatching length of labels for sentence" << i << "\n"; abort(); } for ( unsigned int n = 0 ; n < N ; ++n, ++numtag ) { int clabel = goldS[i][n]; int cclass = class_type( clabel ); int cbraket = braket_type( n, goldS[i] ); if ( cbraket == SBrac || cbraket == BBrac ) { ccount[cclass]++; } int plabel = predicted[i][n]; int pclass = class_type( plabel ); int pbraket = braket_type( n, predicted[i] ); if ( pbraket == SBrac || pbraket == BBrac ) { pcount[pclass]++; } if ( cbraket == pbraket ) numbtag++; if ( clabel == plabel && cbraket == pbraket ) numctag++; if ( pbraket == SBrac && cbraket == SBrac ) { nbcorrect[pclass]++; nbleft[pclass]++; nbright[pclass]++; if( pclass == cclass ) { ncorrect[pclass]++; nleft[pclass]++; nright[pclass]++; } } else if ( pbraket == SBrac && cbraket == EBrac ) { nbright[pclass]++; if( pclass == cclass ) { nright[pclass]++; } } else if ( pbraket == SBrac && cbraket == BBrac ) { nbleft[pclass]++; if( pclass == cclass ) { nleft[pclass]++; } } else if ( pbraket == BBrac && cbraket == SBrac ) { nbleft[pclass]++; if( pclass == cclass ) { nleft[pclass]++; } } else if ( pbraket == BBrac && cbraket == BBrac ) { nbleft[pclass]++; bmatch=1; if( pclass == cclass ) { nleft[pclass]++; match=1;} } /* if ( pbraket != cbraket ) bmatch = 0; if (!(clabel == plabel && cbraket == pbraket ) ) match = 0; if ( pbraket == none || cbraket == none ) match=bmatch=0; */ if ( pbraket != cbraket || pbraket == none ) bmatch = 0; if ( cclass != pclass || !bmatch ) match = 0; if ( pbraket == EBrac && cbraket == SBrac ) { nbright[pclass]++; if( pclass == cclass ) { nright[pclass]++; } } if ( pbraket == EBrac && cbraket == EBrac ) { if( bmatch ) nbcorrect[pclass]++; nbright[pclass]++; if( pclass == cclass ) { if ( match && ncorrect[pclass] <= pcount[pclass]) ncorrect[pclass]++; nright[pclass]++; } } } } Float score; int numans = getsum( pcount ); int numref = getsum( ccount ); if (verbose) { out << "\n[Tagging Performance]\n"; out << "# of tags: " << numtag << ",\t correct tags: " << numctag << ",\t correct IOBs: " << numbtag << "\n"; out << "precision with class info: " << (float)numctag/numtag; out << ",\t w/o class info: " << (float)numbtag/numtag << "\n"; out << "\n[Object Identification Performance]\n"; out << "# of OBJECTs: " << numref << "\t ANSWERs: " << numans << ".\n"; out << "\n# (recall / precision / f-score) of ...\n"; } if ( !numref ) cerr << "\n\nNo names in reference!\n"; if ( !numans ) cerr << "\n\nNo names in answers!\n"; Float ret_val = compute_score( getsum(ncorrect), numans, numref , "FULLY CORRECT answer", verbose, out); /* There is a bug on the right score = compute_score( getsum(nleft), numans, numref , "correct LEFT boundary", verbose, out ); score = compute_score( getsum(nright), numans, numref , "correct RIGHT boundary", verbose, out ); */ if (num_class > 2 && verbose ) for( unsigned int cl = 1 ; cl < pcount.size() ; ++cl ) { string cl_str = LIS[reverse_class_type(cl)]; out << "\n[" << cl << "/" << string(cl_str,2,int(cl_str.size()-2)) << "\tIdentification Performance]\n"; out << "# of OBJECTs: " << ccount[cl] << ",\t ANSWERs: " << pcount[cl]; out << "\n# (recall / precision / f-score) of ...\n"; score = compute_score( ncorrect[cl], pcount[cl], ccount[cl] , "FULLY CORRECT answer", verbose, out ); /* score = compute_score( nleft[cl], pcount[cl], ccount[cl] , "correct LEFT boundary", verbose, out ); score = compute_score( nright[cl], pcount[cl], ccount[cl] , "correct RIGHT boundary", verbose, out ); */ } else if ( !verbose ) for( unsigned int cl = 1 ; cl < pcount.size() ; ++cl ) { score = compute_score( ncorrect[cl], pcount[cl], ccount[cl] , "FULLY CORRECT answer", verbose, out ); cerr << "Cl:" << cl << " " << score << " "; } //assert(ret_val<=1.0); if (ret_val>1.0) ret_val=1.0; return ret_val; }
Float evaluate_sequences(vector<vector<int> > &goldS,vector<vector<int> > &predicted,vector<string> &LIS ,int num_labels,vector<verbose_res> &VR){ int numtag,numctag,numbtag; numtag=numctag=numbtag=0; int num_class = ( num_labels / 2 ) + 1; vector<int> ccount(num_class,0),pcount(num_class,0),ncorrect(num_class,0), nleft(num_class,0),nright(num_class,0), nbcorrect(num_class,0),nbleft(num_class,0),nbright(num_class,0); int match,bmatch; match=bmatch=0; int num_seq = goldS.size(); for (int i = 0; i < num_seq ; ++i){ // For each sequence unsigned int N = goldS[i].size(); if ( N != predicted[i].size() ) { cerr << "Unmatching length of labels for sentence" << i << "\n"; abort(); } for ( unsigned int n = 0 ; n < N ; ++n, ++numtag ) { int clabel = goldS[i][n]; int cclass = class_type( clabel ); int cbraket = braket_type( n, goldS[i] ); if ( cbraket == SBrac || cbraket == BBrac ) { ccount[cclass]++; } int plabel = predicted[i][n]; int pclass = class_type( plabel ); int pbraket = braket_type( n, predicted[i] ); if ( pbraket == SBrac || pbraket == BBrac ) { pcount[pclass]++; } if ( cbraket == pbraket ) numbtag++; if ( clabel == plabel && cbraket == pbraket ) numctag++; if ( pbraket == SBrac && cbraket == SBrac ) { nbcorrect[pclass]++; nbleft[pclass]++; nbright[pclass]++; if( pclass == cclass ) { ncorrect[pclass]++; nleft[pclass]++; nright[pclass]++; } } else if ( pbraket == SBrac && cbraket == EBrac ) { nbright[pclass]++; if( pclass == cclass ) { nright[pclass]++; } } else if ( pbraket == SBrac && cbraket == BBrac ) { nbleft[pclass]++; if( pclass == cclass ) { nleft[pclass]++; } } else if ( pbraket == BBrac && cbraket == SBrac ) { nbleft[pclass]++; if( pclass == cclass ) { nleft[pclass]++; } } else if ( pbraket == BBrac && cbraket == BBrac ) { nbleft[pclass]++; bmatch=1; if( pclass == cclass ) { nleft[pclass]++; match=1;} } if ( pbraket != cbraket || pbraket == none ) bmatch = 0; if ( cclass != pclass || !bmatch ) match = 0; if ( pbraket == EBrac && cbraket == SBrac ) { nbright[pclass]++; if( pclass == cclass ) { nright[pclass]++; } } if ( pbraket == EBrac && cbraket == EBrac ) { if( bmatch ) nbcorrect[pclass]++; nbright[pclass]++; if( pclass == cclass ) { if ( match && ncorrect[pclass] <= pcount[pclass]) ncorrect[pclass]++; nright[pclass]++; } } } } Float score; int numans = getsum(pcount), numref = getsum(ccount); verbose_res vr("ALL",int(numref),int(numans)); if ( !numref ) cerr << "\n\nNo names in reference!\n"; if ( !numans ) cerr << "\n\nNo names in answers!\n"; Float ret_val = compute_score(getsum(ncorrect),numans,numref,"FULLY CORRECT answer",vr); VR.push_back(vr); if (num_class > 2) for( unsigned int cl = 1 ; cl < pcount.size() ; ++cl ) { string cl_str = LIS[reverse_class_type(cl)]; verbose_res vr_cl(string(cl_str,2,int(cl_str.size()-2)),ccount[cl],pcount[cl]); score = compute_score(ncorrect[cl],pcount[cl],ccount[cl],"FULLY CORRECT answer",vr_cl); VR.push_back(vr_cl); } if (ret_val>1.0) ret_val=1.0; return ret_val; }