main() { char s[10],o[10],c; FILE *fp=fopen("input.txt","r"); fscanf(fp,"%s",s); fclose(fp); int i=0; for(i=0;i<strlen(s);i++) { if(s[i]>=96 && s[i]<=123) o[f++]=s[i]; else if(s[i]=='+' || s[i]=='-' || s[i]=='*' || s[i]=='/'|| s[i]=='^') { while(prec(peek(&stck))>=prec(s[i]) && stck.next!=NULL) o[f++]=pop(&stck); push(&stck,s[i]); } else if(s[i]=='(') push(&stck,'('); else if(s[i]==')') { while(peek(&stck)!='(') o[f++]=pop(&stck); c=pop(&stck); } } while(stck.next!=NULL) o[f++]=pop(&stck); o[f]='\0'; /* for(i=0;i<f;i++) printf("%c",o[i]); printf("\n"); */ printf("%s\n",o); }
/* * Function for evaluating the innermost parts of expressions, * viz. !expr (expr) number defined(symbol) symbol * We reset the constexpr flag in the last two cases. */ static Linetype eval_unary(const struct ops *ops, int *valp, const char **cpp) { const char *cp; char *ep; int sym; bool defparen; Linetype lt; cp = skipcomment(*cpp); if (*cp == '!') { debug("eval%d !", prec(ops)); cp++; lt = eval_unary(ops, valp, &cp); if (lt == LT_ERROR) return (LT_ERROR); if (lt != LT_IF) { *valp = !*valp; lt = *valp ? LT_TRUE : LT_FALSE; } } else if (*cp == '(') { cp++; debug("eval%d (", prec(ops)); lt = eval_table(eval_ops, valp, &cp); if (lt == LT_ERROR) return (LT_ERROR); cp = skipcomment(cp); if (*cp++ != ')') return (LT_ERROR); } else if (isdigit((unsigned char)*cp)) { debug("eval%d number", prec(ops)); *valp = strtol(cp, &ep, 0); if (ep == cp) return (LT_ERROR); lt = *valp ? LT_TRUE : LT_FALSE; cp = skipsym(cp); } else if (strncmp(cp, "defined", 7) == 0 && endsym(cp[7])) { cp = skipcomment(cp+7); debug("eval%d defined", prec(ops)); if (*cp == '(') { cp = skipcomment(cp+1); defparen = true; } else { defparen = false; } sym = findsym(cp); if (sym < 0) { lt = LT_IF; } else { *valp = (value[sym] != NULL); lt = *valp ? LT_TRUE : LT_FALSE; } cp = skipsym(cp); cp = skipcomment(cp); if (defparen && *cp++ != ')') return (LT_ERROR); constexpr = false; } else if (!endsym(*cp)) {
int main(){ int n; Stack s; s=empty(); char c; char posfija[100]; int largo=0; int flag=0; // Se pasa a posfija while(1){ if(!flag) scanf("%c",&c); else flag=0; if(c=='\n' || c=='\0') break; if(c=='('||c=='{'||c=='[') s=push(c,s); else if(c==')' || c=='}' || c==']'){ char a=top(s); while(a!='(' && a!='{' && a!='['){ posfija[largo++]=a; s=pop(s); a=top(s); } s=pop(s); } else if(esOperando(c)==1){ posfija[largo++]=c; scanf("%c",&c); while(esOperando(c)){ if(c=='\n' || c=='\0'){ flag=1; break; } posfija[largo++]=c; scanf("%c",&c); } posfija[largo++]=','; flag=1; continue; } else if(esOperador(c)){ while(!isEmpty(s) && (prec(top(s))>= prec(c))){ posfija[largo++]=top(s); s=pop(s); } s=push(c,s); } } while(!isEmpty(s)){ posfija[largo++]=top(s); s=pop(s); } // Se termina la conversion printf("%.2lf\n",evaluar(posfija, largo)); return 0; }
int main() { Teuchos::SerialDenseMatrix<int, double> A(5,5); Teuchos::SerialDenseMatrix<int, double> B(5,1); Teuchos::SerialDenseMatrix<int, double> X(5,1); /* for (double i=0; i<A.numRows();i++){ for (double j=0; j<A.numRows();j++){ A(i,j)=1/(i+j+1); }}*/ for (int i=0; i<A.numRows(); i++){ A(0,i)=1; A(i,0)=1; } A(1,1)=2; A(1,2)=3;A(1,3)=4;A(1,4)=5; A(2,1)=3; A(2,2)=6;A(2,3)=10;A(2,4)=15; A(3,1)=4; A(3,2)=10;A(3,3)=20;A(3,4)=35; A(4,1)=5; A(4,2)=15;A(4,3)=35;A(4,4)=70; B.putScalar(1.0); X.putScalar(0.0); int maxit=40; double tolerance=1e-6; Stokhos::DiagPreconditioner<int,double> prec(A); CG(A,X,B,maxit,tolerance, prec); return 0; }
void Schedule::dumpContexts() { ContextRelation *it; qDebug() << "SCHEDULE DUMP:"; QString dump; QTextStream out(&dump); for (OutputContext *ctx = _contextRoot.next(); !ctx->isRoot(); ctx = ctx->next()) { out << ctx << " (left:" << ctx->leftEdge() << ", right: " << ctx->rightEdge() << ")"; QScopedPointer<ContextRelation> prec(list(Preceding, ctx)); QScopedPointer<ContextRelation> fol(list(Following, ctx)); out << "\n Preceded by: "; for (it = prec->next(); !it->isRoot(); it = it->next()) out << it->source() << " "; out << "\n Followed by: "; for (it = fol->next(); !it->isRoot(); it = it->next()) out << it->target() << " "; out << "\n Text: `" << ctx->output() << "'"; qDebug() << dump.toLatin1().data(); dump.clear(); } }
void Saliency::Evaluate(const string gtImgsW, const string &salDir, const string &resName) { vector<vecD> prec(SAL_TYPE_NUM), recall(SAL_TYPE_NUM); static const int SHOW_COLOR_NUM = 7; static const char* colorShow[SHOW_COLOR_NUM] = {"'k'", "'b'", "'g'", "'r'", "'c'", "'m'", "'y'"}; FILE* f = fopen(resName.c_str(), "w"); CV_Assert(f != NULL); fprintf(f, "clear;\nclose all;\nclc;\nhold on;\nfigure(1);\n\n"); #pragma omp parallel for for (int i = 0; i < SAL_TYPE_NUM; i++) Evaluate(salDir + "*" + SAL_TYPE_DES[i] + ".png", gtImgsW, prec[i], recall[i]); string leglendStr("legend("); for (int i = 0; i < SAL_TYPE_NUM; i++) { string strPre = format("Precision%s", SAL_TYPE_DES[i]); string strRecal = format("Recall%s", SAL_TYPE_DES[i]); int dim = PrintVector(f, recall[i], strRecal); PrintVector(f, prec[i], strPre, dim); fprintf(f, "plot(%s, %s, %s, 'linewidth', 2);\n\n", strRecal.c_str(), strPre.c_str(), colorShow[i % SHOW_COLOR_NUM]); leglendStr += format("'%s', ", SAL_TYPE_DES[i] + 1); } leglendStr.resize(leglendStr.size() - 2); leglendStr += ");"; fprintf(f, "hold off;\nxlabel('Recall');\nylabel('Precision');\n\n%s\ngrid on;\n", leglendStr.c_str()); fprintf(f, "\n\nfigure(2);hold on;\n"); for (int i = 0; i < SAL_TYPE_NUM; i++) fprintf(f, "plot(Recall%s, %s, 'linewidth', 2);\n", SAL_TYPE_DES[i], colorShow[i % SHOW_COLOR_NUM]); fprintf(f, "%s\nhold off;\nxlabel('Threshold');\nylabel('Recall');\ngrid on;", leglendStr.c_str()); fclose(f); CmLog::LogProgress("Evaluation finished%-40s\n", ""); }
void TestSolver::circle2() { const ExprSymbol& x=ExprSymbol::new_("x"); const ExprSymbol& y=ExprSymbol::new_("y"); SystemFactory f; f.add_var(x); f.add_var(y); f.add_ctr(sqr(x)+sqr(y)=1); f.add_ctr(sqr(x-2)+sqr(y)=1); double _sol1[]={1,0}; Vector sol1(2,_sol1); System sys(f); RoundRobin rr(1e-3); CellStack stack; CtcHC4 hc4(sys); Vector prec(2,1e-3); Solver solver(sys,hc4,rr,stack,prec,prec); solver.start(IntervalVector(2,Interval(-10,10))); CovSolverData::BoxStatus status; bool res=solver.next(status); CPPUNIT_ASSERT(res); CPPUNIT_ASSERT(status==CovSolverData::UNKNOWN); CPPUNIT_ASSERT(solver.get_data().nb_unknown()==1); CPPUNIT_ASSERT(solver.get_data().unknown(0).is_superset(sol1)); res=solver.next(status); CPPUNIT_ASSERT(!res); }
void infix_to_postfix (char infix [ ]) { int length; int index = 0, pos= 0; char symbol, temp; char postfix [50]; length = strlen(infix); infix[length]=')'; push('('); while (index <= length) { symbol = infix[index]; switch (symbol) { case '(' : push (symbol); break; case ')' : temp = pop ( ); while (temp != '(') { postfix [pos]=temp; pos++; temp=pop (); } break; case '+' : case '-' : case '*' : case '/' : case '^' : while (prec (stack[top]) >= prec (symbol)) { temp = pop(); postfix [pos]= temp; pos++; } push (symbol); break; default:postfix [pos++] = symbol; break; } index++; } postfix [pos++] = '\0'; printf("\nEquivalent postfix expression is:\n"); puts (postfix); return; }
void coinpos(stack *s) { //infix to postfix printf("\n Enter the infix expression : "); scanf(" %s",a); int len=strlen(a); printf("\n Length of above expression is : %d \n",len); printf("\n The postfix expression is :\t"); for(i=0; i<len ; i++) { if(check(a[i])==0) //operand printf("%c",a[i]); else if(a[i]=='(') push(s,'('); else { if(a[i]==')') while((x=pop(s))!='(') printf("%c",x); else { while(prec(a[i])<=prec(top(s)) && !empty(s)) { x=pop(s); } push(s,a[i]); printf("%c",x); } } } while(!empty(s)) { x=pop(s); printf("%c",x); } printf("\n\n"); options(s); }
static void chekit(int no) { /* deal with operator */ if (flag && newx) equals(no); else newx=FALSE; flag=ON; copy(x,y[sp]); op[sp]=no; prop[sp]=prec(no); }
void goal::display(ast_printer & prn, std::ostream & out) const { out << "(goal"; unsigned sz = size(); for (unsigned i = 0; i < sz; i++) { out << "\n "; prn.display(out, form(i), 2); } out << "\n :precision " << prec() << " :depth " << depth() << ")" << std::endl; }
int LSmear::var_to_bisect(IntervalMatrix& J, const IntervalVector& box) const { int lvar = -1; //Linearization LPSolver::Status_Sol stat = LPSolver::UNKNOWN; Vector dual_solution(1); if (lsmode==LSMEAR_MG) { //compute the Jacobian in the midpoint IntervalMatrix J2(sys.f_ctrs.image_dim(), sys.nb_var); IntervalVector box2(IntervalVector(box.mid()).inflate(1e-8)); // IntervalVector box2(IntervalVector(box.random())); box2 &= box; sys.f_ctrs.jacobian(box2,J2); stat = getdual(J2, box, dual_solution); } else if (lsmode==LSMEAR) { stat = getdual(J, box, dual_solution); } if (stat == LPSolver::OPTIMAL) { double max_Lmagn = 0.0; int k=0; for (int j=0; j<nbvars; j++) { Interval lsmear=Interval(0.0); if ((!too_small(box,j)) && (box[j].mag() <1 || box[j].diam()/ box[j].mag() >= prec(j))){ lsmear=dual_solution[j]; for (int i=0; i<sys.f_ctrs.image_dim(); i++){ lsmear += dual_solution[sys.nb_var+i] * J[i][j]; } } lsmear*=(box[j].diam()); if (lsmear.mag() > 1e-10 && (j!=goal_var() || mylinearsolver->get_obj_value().mid() > box[goal_var()].lb() )) { k++; if (lsmear.mag() > max_Lmagn) { max_Lmagn = lsmear.mag(); lvar = j; } } } if (k==1 && lvar==goal_var()) { lvar=-1; } } if (lvar==-1) { // std::cout << "ssr " << std::endl; lvar=SmearSumRelative::var_to_bisect(J, box); } // std::cout << "lsmear " << lvar << std::endl; return lvar; }
// The main function that converts given infix expression // to postfix expression. int infixToPostfix(char* exp) { int i,k; struct stack s; s.top=-1; //char* output = (char *)malloc(sizeof(exp)*sizeof(char)); // ^^ for using another string for output: replace exp[++k] with output[++k] for (i=0, k=-1; exp[i]; ++i) { // here exp[i] is the scanned character going from left to right // If the scanned character is an operand, add it to output. if (isOperand(exp[i])) exp[++k] = exp[i]; // If the scanned character is an ‘(‘, push it to the stack. else if (exp[i]=='(') push(&s, exp[i]); // If the scanned character is an ‘)’, pop and output from the stack // until an ‘(‘ is encountered. else if (exp[i]==')') { while (!isEmpty(&s) && peek(&s)!='(') exp[++k] = pop(&s); if (!isEmpty(&s) && peek(&s)!='(') return -1; // invalid expression else pop(&s); } // an operator is encountered else { while ( !isEmpty(&s) && prec(exp[i]) <= prec(peek(&s)) ) exp[++k] = pop(&s); push(&s, exp[i]); } } // pop all the operators from the stack while (!isEmpty(&s)) exp[++k] = pop(&s); exp[++k] = '\0'; printf("\n\tPostfix expression: %s\n", exp); return 0; }
void AddrMem::convertType(ostream& os) const { os << "("; os << PrecType::getName(prec()); if (vecLength() > 1) os << vecLength(); os << ")"; }
void AddrMem::declareType(ostream& os) const { os << _addrSpace.str(); if (_isConst) os << "const "; os << PrecType::getName(prec()); if (vecLength() > 1) os << vecLength(); os << (_isPointer ? " * " : " "); }
void TestSolver::circle4() { const ExprSymbol& x=ExprSymbol::new_("x"); const ExprSymbol& y=ExprSymbol::new_("y"); const ExprSymbol& r2=ExprSymbol::new_("r2"); SystemFactory f; f.add_var(x); f.add_var(y); f.add_var(r2); f.add_ctr(sqr(x)+sqr(y)=r2); f.add_ctr(sqr(x-1)+sqr(y)=r2); double cospi6=0.5; double sinpi6=::sqrt(3)/2; double _sol1[]={cospi6,sinpi6,1}; double _sol2[]={cospi6,-sinpi6,1}; Vector sol1(3,_sol1); Vector sol2(3,_sol2); System sys(f); RoundRobin rr(1e-3); CellStack stack; CtcHC4 hc4(sys); VarSet params(sys.f_ctrs,sys.args[2],false); Vector prec(3,1e-3); Solver solver(sys,hc4,rr,stack,prec,prec); solver.set_params(params); IntervalVector box(3); box[0]=Interval(-10,10); box[1]=Interval(-10,10); box[2]=Interval(1,1); solver.start(box); CovSolverData::BoxStatus status; bool res=solver.next(status); CPPUNIT_ASSERT(res); CPPUNIT_ASSERT(status==CovSolverData::SOLUTION); CPPUNIT_ASSERT(solver.get_data().nb_solution()==1); CPPUNIT_ASSERT(solver.get_data().solution(0).is_superset(sol1)); res=solver.next(status); CPPUNIT_ASSERT(status==CovSolverData::SOLUTION); CPPUNIT_ASSERT(solver.get_data().nb_solution()==2); CPPUNIT_ASSERT(solver.get_data().solution(1).is_superset(sol2)); res=solver.next(status); CPPUNIT_ASSERT(!res); }
int main() { char infix[100],postfix[100]="",temp; int i,j,g=0,valid=1; printf(" Enter Infix Expression : "); scanf("%s",infix); for(i=0;infix[i]&&valid;i++) { char c=infix[i]; if(c=='(') push('('); else if(isalnum(c)) postfix[g++]=c; else if(c==')') { while((temp=pop())!='(' && temp!=0) postfix[g++]=temp; if(temp==0) valid=0; } else if(prec(c)) { while((temp=pop())!=0 && prec(temp)>=prec(c)) postfix[g++]=temp; if(temp!=0) push(temp); push(c); } else valid=0; } while((temp=pop())!=0) postfix[g++]=temp; if(valid) printf(" Postfix Expression : %s\n",postfix); else printf(" Invalid Expression "); }
/*@ requires HYPOTHESE_RAM_0_iter_prec : PREC_I_RE1 == 0 ; */ void iter_prec() { INTEGER k=0; /*@ loop invariant I1_1 : k>=0; loop invariant I1_2 : k==0 ==> PREC_I_RE1==0; loop invariant I1_3 : k>=1 ==> PREC_I_RE1==E1[k-1]; */ while (1) { prec(k); k++; } }
void goal::copy_to(goal & target) const { SASSERT(&m_manager == &(target.m_manager)); if (this == &target) return; m().copy(m_forms, target.m_forms); m().copy(m_proofs, target.m_proofs); m().copy(m_dependencies, target.m_dependencies); target.m_depth = std::max(m_depth, target.m_depth); SASSERT(target.m_proofs_enabled == m_proofs_enabled); SASSERT(target.m_core_enabled == m_core_enabled); target.m_inconsistent = m_inconsistent; target.m_precision = mk_union(prec(), target.prec()); }
int main() { int i,k=0; printf("Enter the infix expression\n"); scanf("%s",infix); for(i=0;infix[i]!='\0';i++) { if(infix[i]>='a' && infix[i]<='z') { postfix[k]=infix[i]; k++; } else if(infix[i]=='(') push(infix[i]); else if(infix[i]==')') { while(stack[top]!='(') { postfix[k]=pop(); k++; } pop(); } else { while(prec(infix[i])<=prec(stack[top])) { postfix[k]=pop(); k++; } push(infix[i]); } } printf("Given infix expression is %s and the postfix expression is %s\n",infix,postfix); return 0; }
void TestSolver::circle3() { const ExprSymbol& x=ExprSymbol::new_("x"); const ExprSymbol& y=ExprSymbol::new_("y"); SystemFactory f; f.add_var(x); f.add_var(y); f.add_ctr(sqr(x)+sqr(y)=1); f.add_ctr(sqr(x-1)+sqr(y)=1); double cospi6=0.5; double sinpi6=(sqrt(Interval(3))/2).lb(); f.add_ctr(4*y*abs(y)<=3); // a rigorous way to impose y<=sin(pi/6). double _sol1[]={cospi6,sinpi6}; double _sol2[]={cospi6,-sinpi6}; Vector sol1(2,_sol1); Vector sol2(2,_sol2); System sys(f); RoundRobin rr(1e-3); CellStack stack; CtcHC4 hc4(sys); Vector prec(2,1e-3); Solver solver(sys,hc4,rr,stack,prec,prec); solver.start(IntervalVector(2,Interval(-10,10))); CovSolverData::BoxStatus status; bool res=solver.next(status); CPPUNIT_ASSERT(res); CPPUNIT_ASSERT(status==CovSolverData::UNKNOWN); CPPUNIT_ASSERT(solver.get_data().nb_unknown()==1); CPPUNIT_ASSERT(solver.get_data().unknown(0).is_superset(sol1)); res=solver.next(status); CPPUNIT_ASSERT(res); CPPUNIT_ASSERT(status==CovSolverData::SOLUTION); CPPUNIT_ASSERT(solver.get_data().nb_solution()==1); CPPUNIT_ASSERT(solver.get_data().solution(0).is_superset(sol2)); res=solver.next(status); CPPUNIT_ASSERT(!res); }
void goal::display_with_dependencies(ast_printer & prn, std::ostream & out) const { ptr_vector<expr> deps; obj_hashtable<expr> to_pp; out << "(goal"; unsigned sz = size(); for (unsigned i = 0; i < sz; i++) { out << "\n |-"; deps.reset(); m().linearize(dep(i), deps); ptr_vector<expr>::iterator it = deps.begin(); ptr_vector<expr>::iterator end = deps.end(); for (; it != end; ++it) { expr * d = *it; if (is_uninterp_const(d)) { out << " " << mk_ismt2_pp(d, m()); } else { out << " #" << d->get_id(); to_pp.insert(d); } } out << "\n "; prn.display(out, form(i), 2); } if (!to_pp.empty()) { out << "\n :dependencies-definitions ("; obj_hashtable<expr>::iterator it = to_pp.begin(); obj_hashtable<expr>::iterator end = to_pp.end(); for (; it != end; ++it) { expr * d = *it; out << "\n (#" << d->get_id() << "\n "; prn.display(out, d, 2); out << ")"; } out << ")"; } out << "\n :precision " << prec() << " :depth " << depth() << ")" << std::endl; }
void goal::display_with_dependencies(std::ostream & out) const { ptr_vector<expr> deps; out << "(goal"; unsigned sz = size(); for (unsigned i = 0; i < sz; i++) { out << "\n |-"; deps.reset(); m().linearize(dep(i), deps); ptr_vector<expr>::iterator it = deps.begin(); ptr_vector<expr>::iterator end = deps.end(); for (; it != end; ++it) { expr * d = *it; if (is_uninterp_const(d)) { out << " " << mk_ismt2_pp(d, m()); } else { out << " #" << d->get_id(); } } out << "\n " << mk_ismt2_pp(form(i), m(), 2); } out << "\n :precision " << prec() << " :depth " << depth() << ")" << std::endl; }
void pFluid::updateCloud() { CK3dPointCloud *cloud = getPointCloud(); if (!cloud) return; CKMesh *mesh = getParticleObject()->GetCurrentMesh(); int count = mesh->GetVertexCount(); VxVector *points = new VxVector[count]; if (mParticleBuffer) { for (int i = 0 ; i < mesh->GetVertexCount() ; i++) { pParticle *p = &mParticleBuffer[i]; if (p) { points[i]= getFrom(p->position); } } } VxVector prec(0.5,0.5,0.5); VxVector a[10]; int b = cloud->CreateFromPointList(2,a,NULL,NULL,NULL,prec); if (b) { int op2=2; op2++; } }
bool AddrMem::fp64(void) const { return PrecType::Double == prec(); }
char *TessPDFRenderer::GetPDFTextObjects(TessBaseAPI *api, double width, double height) { STRING pdf_str(""); double ppi = api->GetSourceYResolution(); // These initial conditions are all arbitrary and will be overwritten double old_x = 0.0, old_y = 0.0; int old_fontsize = 0; tesseract::WritingDirection old_writing_direction = WRITING_DIRECTION_LEFT_TO_RIGHT; bool new_block = true; int fontsize = 0; double a = 1; double b = 0; double c = 0; double d = 1; // TODO(jbreiden) This marries the text and image together. // Slightly cleaner from an abstraction standpoint if this were to // live inside a separate text object. pdf_str += "q "; pdf_str.add_str_double("", prec(width)); pdf_str += " 0 0 "; pdf_str.add_str_double("", prec(height)); pdf_str += " 0 0 cm /Im1 Do Q\n"; ResultIterator *res_it = api->GetIterator(); while (!res_it->Empty(RIL_BLOCK)) { if (res_it->IsAtBeginningOf(RIL_BLOCK)) { pdf_str += "BT\n3 Tr"; // Begin text object, use invisible ink old_fontsize = 0; // Every block will declare its fontsize new_block = true; // Every block will declare its affine matrix } int line_x1, line_y1, line_x2, line_y2; if (res_it->IsAtBeginningOf(RIL_TEXTLINE)) { int x1, y1, x2, y2; res_it->Baseline(RIL_TEXTLINE, &x1, &y1, &x2, &y2); ClipBaseline(ppi, x1, y1, x2, y2, &line_x1, &line_y1, &line_x2, &line_y2); } if (res_it->Empty(RIL_WORD)) { res_it->Next(RIL_WORD); continue; } // Writing direction changes at a per-word granularity tesseract::WritingDirection writing_direction; { tesseract::Orientation orientation; tesseract::TextlineOrder textline_order; float deskew_angle; res_it->Orientation(&orientation, &writing_direction, &textline_order, &deskew_angle); if (writing_direction != WRITING_DIRECTION_TOP_TO_BOTTOM) { switch (res_it->WordDirection()) { case DIR_LEFT_TO_RIGHT: writing_direction = WRITING_DIRECTION_LEFT_TO_RIGHT; break; case DIR_RIGHT_TO_LEFT: writing_direction = WRITING_DIRECTION_RIGHT_TO_LEFT; break; default: writing_direction = old_writing_direction; } } } // Where is word origin and how long is it? double x, y, word_length; { int word_x1, word_y1, word_x2, word_y2; res_it->Baseline(RIL_WORD, &word_x1, &word_y1, &word_x2, &word_y2); GetWordBaseline(writing_direction, ppi, height, word_x1, word_y1, word_x2, word_y2, line_x1, line_y1, line_x2, line_y2, &x, &y, &word_length); } if (writing_direction != old_writing_direction || new_block) { AffineMatrix(writing_direction, line_x1, line_y1, line_x2, line_y2, &a, &b, &c, &d); pdf_str.add_str_double(" ", prec(a)); // . This affine matrix pdf_str.add_str_double(" ", prec(b)); // . sets the coordinate pdf_str.add_str_double(" ", prec(c)); // . system for all pdf_str.add_str_double(" ", prec(d)); // . text that follows. pdf_str.add_str_double(" ", prec(x)); // . pdf_str.add_str_double(" ", prec(y)); // . pdf_str += (" Tm "); // Place cursor absolutely new_block = false; } else { double dx = x - old_x; double dy = y - old_y; pdf_str.add_str_double(" ", prec(dx * a + dy * b)); pdf_str.add_str_double(" ", prec(dx * c + dy * d)); pdf_str += (" Td "); // Relative moveto } old_x = x; old_y = y; old_writing_direction = writing_direction; // Adjust font size on a per word granularity. Pay attention to // fontsize, old_fontsize, and pdf_str. We've found that for // in Arabic, Tesseract will happily return a fontsize of zero, // so we make up a default number to protect ourselves. { bool bold, italic, underlined, monospace, serif, smallcaps; int font_id; res_it->WordFontAttributes(&bold, &italic, &underlined, &monospace, &serif, &smallcaps, &fontsize, &font_id); const int kDefaultFontsize = 8; if (fontsize <= 0) fontsize = kDefaultFontsize; if (fontsize != old_fontsize) { char textfont[20]; snprintf(textfont, sizeof(textfont), "/f-0-0 %d Tf ", fontsize); pdf_str += textfont; old_fontsize = fontsize; } } bool last_word_in_line = res_it->IsAtFinalElement(RIL_TEXTLINE, RIL_WORD); bool last_word_in_block = res_it->IsAtFinalElement(RIL_BLOCK, RIL_WORD); STRING pdf_word(""); int pdf_word_len = 0; do { const char *grapheme = res_it->GetUTF8Text(RIL_SYMBOL); if (grapheme && grapheme[0] != '\0') { // TODO(jbreiden) Do a real UTF-16BE conversion // http://en.wikipedia.org/wiki/UTF-16#Example_UTF-16_encoding_procedure string_32 utf32; CubeUtils::UTF8ToUTF32(grapheme, &utf32); char utf16[20]; for (int i = 0; i < static_cast<int>(utf32.length()); i++) { snprintf(utf16, sizeof(utf16), "<%04X>", utf32[i]); pdf_word += utf16; pdf_word_len++; } } delete[]grapheme; res_it->Next(RIL_SYMBOL); } while (!res_it->Empty(RIL_BLOCK) && !res_it->IsAtBeginningOf(RIL_WORD)); if (word_length > 0 && pdf_word_len > 0 && fontsize > 0) { double h_stretch = kCharWidth * prec(100.0 * word_length / (fontsize * pdf_word_len)); pdf_str.add_str_double("", h_stretch); pdf_str += " Tz"; // horizontal stretch pdf_str += " [ "; pdf_str += pdf_word; // UTF-16BE representation pdf_str += " ] TJ"; // show the text } if (last_word_in_line) { pdf_str += " \n"; } if (last_word_in_block) { pdf_str += "ET\n"; // end the text object } } char *ret = new char[pdf_str.length() + 1]; strcpy(ret, pdf_str.string()); delete res_it; return ret; }
bool goal::sat_preserved() const { return prec() == PRECISE || prec() == UNDER; }
void coinpre(stack *s) { //infix to prefix printf("\n Enter the infix expression : "); scanf(" %s",a); int len=strlen(a); int c[30]; int j=0; int count=0; printf("\n Length of above expression is : %d \n",len); printf("\n The prefix expression is :\t"); for(i=len-1,p1=0; i>=0; i--) { b[p1]=a[i]; p1++; } for(i=0; i<len; i++) { if(check(b[i])==0) c[j++]=b[i]; else if(b[i]==')') { push(s,')'); count+=2; } else { if(b[i]=='(') while(top(s)!=')') c[j++]=pop(s); else //meaning operator { while(prec(b[i])<=prec(top(s)) && !empty(s)) { x=pop(s); c[j++]=x; } push(s,b[i]); } } } while(!empty(s)) { x=pop(s); c[j++]=x; } if(count==2) p2=1; if(count==4) p2=2; if(count==6) p2=3; for(i=len-count-p2; i>=0; i--) { if(c[i]!=')' || c[i]!='(') printf("%c",c[i]); } printf("\n\n"); options(s); }
bool goal::unsat_preserved() const { return prec() == PRECISE || prec() == OVER; }
static void equals(int no) { /* perform binary operation */ BOOL pop; newx=FALSE; pop=TRUE; while (pop) { if (prec(no)>prop[sp]) { /* if higher precedence, keep this one pending */ if (sp==top) { mip->ERNUM=(-1); result=FALSE; newx=TRUE; } else sp++; return; } newx=TRUE; if (flag && op[sp]!=3 && op[sp]!=0) swap(); switch (op[sp]) { case 7: fdiv(x,y[sp],t); ftrunc(t,t,t); fmul(t,y[sp],t); fsub(x,t,x); break; case 6: fpowf(x,y[sp],x); break; case 5: frecip(y[sp],t); fpowf(x,t,x); break; case 4: fdiv(x,y[sp],x); break; case 3: fmul(x,y[sp],x); break; case 2: fsub(x,y[sp],x); break; case 1: fadd(x,y[sp],x); break; case 0: break; } if (sp>0 && (prec(no)<=prop[sp-1])) sp--; else pop=FALSE; } }