int main()
{
    SplayTree st(arrSize);
    int n, op, num;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d%d", &op, &num);
        switch (op)
        {
        case 1:
            st.insert(num);
            break;
        case 2:
            st.remove(num);
            break;
        case 3:
            printf("%d\n", st.rank(num));
            break;
        case 4:
            printf("%d\n", getVal(st.select(num)));
            break;
        case 5:
            printf("%d\n", getVal(st.pred(num)));
            break;
        case 6:
            printf("%d\n", getVal(st.succ(num)));
            break;
        default:
            break;
        }
    }
    return 0;
}
/*!
 * This method sets all the local properties from a vector of pointers
 * to const gchar * strings of Property - Value pairs.
 * This method wipes out all the old values and clears all the bools
 * assciated with them.
 */
void XAP_Dialog_FontChooser::setAllPropsFromVec(const UT_Vector & vProps)
{
	UT_sint32 remCount = vProps.getItemCount();
	if(remCount <= 0)
		return;
	// BAD BAD, we have wrong count
	UT_ASSERT_HARMLESS(remCount % 2 == 0);
	if(remCount % 2) {
		remCount--;
	}
	m_mapProps.clear();
	UT_sint32 i = 0;
	for(i=0; i< remCount; i+=2)
	{
		m_mapProps.insert(std::make_pair((const char*)vProps.getNthItem(i), 
										 (const char*)vProps.getNthItem(i+1)));
	}
//
// Do the Text decorations
//
	const std::string sDecor = getVal("text-decoration");
	m_bUnderline = (NULL != strstr(sDecor.c_str(),"underline"));
	m_bOverline = (NULL != strstr(sDecor.c_str(),"overline"));
	m_bStrikeout = (NULL != strstr(sDecor.c_str(),"line-through"));
	m_bTopline = (NULL != strstr(sDecor.c_str(),"topline"));
	m_bBottomline = (NULL != strstr(sDecor.c_str(),"bottomline"));

	const std::string sDisplay = getVal("display");
	m_bHidden = !strcmp(sDisplay.c_str(),"none");
	
	const std::string sPosition = getVal("text-position");
	m_bSuperScript = strcmp(sPosition.c_str(),"superscript")==0;
	m_bSubScript = strcmp(sPosition.c_str(),"subscript")==0;
}
    int calculate(std::string const& s) { // 44 ms
        if (s.empty() || s.find_first_not_of(" ") == std::string::npos) { return 0; }
        /*
         * since we only have +*-/ four operations, we follow the rules below
         * whenver we see * or /, performs the operation
         * if we see -, just push negative number to stack
         * if we see +, just push the number to stack
         *
         * sume the stack up and get the results.
         */

        std::stack<int> nums;
        int pos = 0;
        nums.push(getVal(s, pos));
        while (pos < s.size() && s.find_first_not_of(" ", pos) != std::string::npos) {
            auto const nextOp  = getOps(s, pos);
            auto nextNum = getVal(s, pos);
            auto curNum  = nums.top();
            switch (nextOp) {
                case '*': nextNum = curNum * nextNum; nums.pop(); break;
                case '/': nextNum = curNum / nextNum; nums.pop(); break;
                case '-': nextNum = -nextNum; break;
                case '+': break;
            }
            nums.push(nextNum);
        }

        int res = 0;
        while (!nums.empty()) { res += nums.top(); nums.pop(); }
        return res;
    }
Exemple #4
0
void parseCType(char *line, unsigned short *comp, unsigned char *dest, unsigned char *jump) {
        *dest = 0;
        *jump = 0;

        char *dpos = strchr(line, '=');
        char *jpos = strchr(line, ';');

        if(jpos != NULL) {
            jpos[0] = '\0';
            jpos++;

            jpos = trim(jpos);

            *jump = getVal(jpos, &jumps);
        }else{
            *jump = KNF;
        }

        if(dpos != NULL) {
            dpos[0] = '\0';
            dpos++;

            dpos = trim(dpos);
            line = trim(line);

            *dest = getVal(line, &dests);
            *comp = getVal(dpos, &ops);
        }else{
            *dest = KNF;
            line = trim(line);
            *comp = getVal(line, &ops);
        }
}
 ListNode *addTwoNumbers(ListNode *l1, ListNode *l2, int carry) {
     if (l1 == NULL && l2 == NULL){
         return (carry == 0) ? NULL : new ListNode(carry);
     }
     int sum = getVal(l1) + getVal(l2) + carry;
     ListNode *l3 = new ListNode(sum % 10);
     l3->next = addTwoNumbers(toNext(l1), toNext(l2), sum / 10);
     return l3;
 }
Exemple #6
0
std::vector<uint8_t> Decode(std::string str)
{
  std::vector<uint8_t> vec ;
  for(int i=0;i+1<(int)str.length();i+=2)
  {
    vec.push_back(getVal(str[i])*16+getVal(str[i+1])) ;
  }
  return vec ;
}
bool XAP_Dialog_FontChooser::getChangedFontFamily(const gchar ** pszFontFamily) const
{
	bool bchanged = didPropChange(m_sFontFamily,getVal("font-family"));
	bool useVal = (bchanged && !m_bChangedFontFamily);
	if (pszFontFamily && useVal)
		*pszFontFamily = getVal("font-family").c_str();
	else if(pszFontFamily)
		*pszFontFamily = m_sFontFamily.c_str();
	return bchanged;
}
bool XAP_Dialog_FontChooser::getChangedTextTransform(const gchar ** pszTextTransform) const
{
	bool bchanged = didPropChange(m_sTextTransform,getVal("text-transform"));
	bool useVal = (bchanged && !m_bChangedTextTransform);
	if (pszTextTransform && useVal)
		*pszTextTransform = getVal("text-transform").c_str();
	else if(pszTextTransform)
		*pszTextTransform = m_sTextTransform.c_str();
	return bchanged;
}
bool XAP_Dialog_FontChooser::getChangedFontWeight(const gchar ** pszFontWeight) const
{
	bool bchanged = didPropChange(m_sFontWeight,getVal("font-weight"));
	bool useVal = (bchanged && !m_bChangedFontWeight);
	if (pszFontWeight && useVal)
		*pszFontWeight = getVal("font-weight").c_str();
	else if(pszFontWeight)
		*pszFontWeight = m_sFontWeight.c_str();
	return bchanged;
}
bool XAP_Dialog_FontChooser::getChangedFontStyle(const gchar ** pszFontStyle) const
{
	bool bchanged = didPropChange(m_sFontStyle,getVal("font-style"));
	bool useVal = (bchanged && !m_bChangedFontStyle);
	if (pszFontStyle && useVal)
		*pszFontStyle = getVal("font-style").c_str();
	else if(pszFontStyle)
		*pszFontStyle = m_sFontStyle.c_str();
	return bchanged;
}
bool XAP_Dialog_FontChooser::getChangedColor(const gchar ** pszColor) const
{
	bool bchanged = didPropChange(m_sColor,getVal("color"));
	bool useVal = (bchanged && !m_bChangedColor);
	if (pszColor && useVal)
		*pszColor = getVal("color").c_str();
	else if(pszColor)
		*pszColor = m_sColor.c_str();
	return bchanged;
}
void ApplicationWindow::updateCtrl(unsigned id)
{
	unsigned ctrl_class = V4L2_CTRL_ID2CLASS(id);
	if (ctrl_class == V4L2_CID_PRIVATE_BASE)
		ctrl_class = V4L2_CTRL_CLASS_USER;

	if (m_ctrlMap[id].flags & CTRL_FLAG_DISABLED)
		return;

	if (!m_haveExtendedUserCtrls && ctrl_class == V4L2_CTRL_CLASS_USER) {
		struct v4l2_control c;

		c.id = id;
		c.value = getVal(id);
		if (ioctl(VIDIOC_S_CTRL, &c)) {
			errorCtrl(id, errno, c.value);
		}
		else if (m_ctrlMap[id].flags & V4L2_CTRL_FLAG_UPDATE)
			refresh(ctrl_class);
		return;
	}
	struct v4l2_ext_control c;
	struct v4l2_ext_controls ctrls;

	memset(&c, 0, sizeof(c));
	memset(&ctrls, 0, sizeof(ctrls));
	c.id = id;
	if (m_ctrlMap[id].type == V4L2_CTRL_TYPE_INTEGER64)
		c.value64 = getVal64(id);
	else if (m_ctrlMap[id].type == V4L2_CTRL_TYPE_STRING) {
		c.size = m_ctrlMap[id].maximum + 1;
		c.string = (char *)malloc(c.size);
		strcpy(c.string, getString(id).toLatin1());
	}
	else
		c.value = getVal(id);
	ctrls.count = 1;
	ctrls.ctrl_class = ctrl_class;
	ctrls.controls = &c;
	if (ioctl(VIDIOC_S_EXT_CTRLS, &ctrls)) {
		errorCtrl(id, errno, c.value);
	}
	else if (m_ctrlMap[id].flags & V4L2_CTRL_FLAG_UPDATE)
		refresh(ctrl_class);
	else {
		if (m_ctrlMap[id].type == V4L2_CTRL_TYPE_INTEGER64)
			setVal64(id, c.value64);
		else if (m_ctrlMap[id].type == V4L2_CTRL_TYPE_STRING) {
			setString(id, c.string);
			free(c.string);
		}
		else
			setVal(id, c.value);
	}
}
Exemple #13
0
//Determines if factor is well-formed
int factor(char list[][20], int size, char* token, int i)
{
    //Factor may begin with identifier
    if(atoi(token) == identsym)
    {
        char* id = list[i+1];
        if(getKind(id) == 1)
            emit(LIT, getLevel(id), getVal(id), i);
        else if (getKind(id) == 2)
        {
            int level = getLevel(id);
            level = abs(lev - level);
            printf("%d %d\n", level, lev);
            emit(LOD, level, getVal(id), i);
        }
        else if (getKind(id) == -1 || getKind(id) == 3) //Identifier cannot be procedure or undeclared
        {
            error(12); err = i; err2 = 12;
            return -1;
        }

        i+=2;
        token = list[i];
    }
    else if(atoi(token) == numbersym) //Factor may begin with number
    {
        emit(LIT, lev, atoi(list[i+1]), i);
        i+=2;
        token = list[i];
    }
    else if(atoi(token) == lparentsym) //Factor may be an expression contained within paratheses
    {
        i++;
        token = list[i];
        i = expression(list, size, token, i);
        if (i == -1)
            return -1;
        token = list[i];
        if(atoi(token) != rparentsym)
        {
            error(9); err = i; err2 = 9;
            return -1;
        }

        i++;
        token = list[i];
    }
    else
    {
        error(10); err = i; err2 = 10;
        return -1;
    }

    return i;
}
Exemple #14
0
void ApplicationWindow::updateCtrl(unsigned id)
{
	unsigned ctrl_class = V4L2_CTRL_ID2CLASS(id);
	if (ctrl_class == V4L2_CID_PRIVATE_BASE)
		ctrl_class = V4L2_CTRL_CLASS_USER;

	if (ctrlMap[id].flags & (V4L2_CTRL_FLAG_READ_ONLY | V4L2_CTRL_FLAG_INACTIVE))
		return;

	if (ctrl_class == V4L2_CTRL_CLASS_USER) {
		struct v4l2_control c;

		c.id = id;
		c.value = getVal(id);
		if (::ioctl(fd, VIDIOC_S_CTRL, &c)) {
			int err = errno;
			char buf[200];

			sprintf(buf, "Error %08x (%s): %s", id,
				ctrlMap[id].name, strerror(err));
			statusBar()->message(buf, 10000);
		}
		return;
	}
	struct v4l2_ext_control c;
	struct v4l2_ext_controls ctrls;

	memset(&c, 0, sizeof(c));
	memset(&ctrls, 0, sizeof(ctrls));
	c.id = id;
	if (ctrlMap[id].type == V4L2_CTRL_TYPE_INTEGER64)
		c.value64 = getVal64(id);
	else
		c.value = getVal(id);
	ctrls.count = 1;
	ctrls.ctrl_class = ctrl_class;
	ctrls.controls = &c;
	if (::ioctl(fd, VIDIOC_S_EXT_CTRLS, &ctrls)) {
		int err = errno;
		char buf[200];

		sprintf(buf, "Error %08x (%s): %s", id,
				ctrlMap[id].name, strerror(err));
		statusBar()->message(buf, 10000);
	}
	else if (ctrlMap[id].flags & V4L2_CTRL_FLAG_UPDATE)
		refresh(ctrl_class);
	else {
		if (ctrlMap[id].type == V4L2_CTRL_TYPE_INTEGER64)
			setVal64(id, c.value64);
		else
			setVal(id, c.value);
	}
}
Exemple #15
0
void GTest_RunCMDLine::setArgs(const QDomElement & el) {
    QString commandLine;
    QDomNamedNodeMap map = el.attributes();
    int mapSz = map.length();
    for( int i = 0; i < mapSz; ++i ) {
        QDomNode node = map.item(i);
        if(node.nodeName() == "message"){
            expectedMessage = node.nodeValue();
            continue;
        }
        if(node.nodeName() == "nomessage"){
            unexpectedMessage = node.nodeValue();
            continue;
        }
        if(node.nodeName() == WORKINK_DIR_ATTR){
            continue;
        }
        QString argument = "--" + node.nodeName() + "=" + getVal(node.nodeValue());
         if( argument.startsWith("--task") ) {
            args.prepend(argument);
            commandLine.prepend(argument + " ");
        } else {
            args.append(argument);
            commandLine.append(argument + " ");
        }
    }
    args.append("--log-level-details");
    args.append("--lang=en");
    args.append("--log-no-task-progress");
    commandLine.append(QString(" --log-level-details --lang=en --log-no-task-progress"));
    cmdLog.info(commandLine);
}
Exemple #16
0
void algoritmo(int soma, int metade, int tamanho, List* partition1, List* partition2, List* listaDeNumeros, int index)
{
        if (soma > metade)
                return;
        if (soma == metade)
        {
                qtdResult++;
                printf("---------------------------------------------\n");
                print(partition1);
                print(partition2);
                printf("---------------------------------------------\n");
                return;
        }

        int i;
        int val;
        List copySet1;
        List copySet2;
        for (i = index; i < tamanho; i++)
        {
                copySet1 = copy(partition1);
                copySet2 = copy(partition2);
                val = getVal(listaDeNumeros, i);
                copySet1.head = addToList(&copySet1, val, true);
                del(&copySet2, val);
                algoritmo(soma + val, metade, tamanho, &copySet1, &copySet2, listaDeNumeros, i + 1);
                destroy(&copySet1);
                destroy(&copySet2);
        }
}
double Chromosome::fTrap() const {

    double result = 0.0;

    for (int i=0; i<length/6; ++i) {
        int u=0;
        for (int j=0; j<6; ++j)
            u += getVal(i*6+j);

        if (u==0)
            result += 1.0;
        else if (u==1)
            result += 0.0;
        else if (u==2)
            result += 0.4;
        else if (u==3)
            result += 0.8;
        else if (u==4)
            result += 0.4;
        else if (u==5)
            result += 0.0;
        else // u == 6
            result += 1.0;
    }

    return result;
}
Exemple #18
0
int read_card_smart(CARD *card, MEMBER *member) {
	int i=0;
	MEMBER *memberCurr = member;
	int ret=SUCCESS;

	strcpy(card->card_id, "");
	strcpy(response, "");
	idx = 0;

	READ[2]=0x00;
	READ[3]=0x00;
	READ[4]=0xFF;

	fprintf(fp, "1. Read Card Smart.About to read Card data:%s\n", card->card_id);
	fflush(fp);

	Ifd_test();

	fprintf(fp, "2. Read Card Smart.About to read Card data:%s\n", card->card_id);
	fflush(fp);

	if(getCardDetails_smart(card, response) == ERROR)
		ret = ERROR; //Get Card details - 0x03

//    strcpy(card->card_id,"WAP052000900023");
    
	fprintf(fp, "3. Read Card Smart.About to read Card data:%s\n", card->card_id);
	fflush(fp);
	sleep(2);

	if (strcmp(card->card_id, "")==0){
		ret=ERROR;
		goto end;
	}

	if (strcmp(getVal("authBio"), "true")==0) {
		if(readMembersFromCard(card, member) == ERROR){
			ret = ERROR;
			goto end;
		}
	} else {
		if (getMemberDetails_rfid(card, member, 0, "") == ERROR) {
			prompt("Error retrieving member data");
			ret=ERROR;
			goto end;
		}
	}

end:	

	SELECT_EF[6]=0x03;
	SCR_Powerdown();

	SCR_Close();
	
	fprintf(fp, "Closing SCR\n");
	fflush(fp);

	return ret;
}
Exemple #19
0
  void operator()(uint64_t hashval) {
    sumCount++;

    // hashval is XXX .. XXX1000.. (w times) ..00 0
    //size_t w = bitScanForward(hashval); // 1-based index of first 1
    size_t w = __builtin_ctz(hashval);

    if (w >= MAX_TABLE) {
      w = MAX_TABLE-1;
    }

    if (M[w] == size*countsPerLong*maxVal) {
      return;
    }

    // hashval is now XXXX...XX, random
    uint64_t hval = hashval >> (w+1); // shift away pattern of XXX10000

    uint64_t index = hval & mask;
    uint64_t val = getVal(index,w);
    if (val != maxVal) { // max count
      setVal(index,w,val+1);
      M[w]++;
    }
  }
// return a given ifkit sensor value as a bool.
bool PhidgetConnector::getBool(int serial_in, int index_in) {
    if(getVal(serial_in, index_in)<500) {
        return false;
    } else {
        return true;
    }
}
Exemple #21
0
int main ()
{
    int i;
    while ( scanf ("%s", input) == 1 ) {

        len_input = strlen (input);
        if ( input [0]=='+'||input [0]=='-' ){
            for ( i = 1; i <= len_input; i++ )
                input [i - 1] = input [i];

                len_input = strlen (input);
            }

        int baseFound = 0;

        int sum = 0;

        for ( i = 0; i < len_input; i++ )
            sum += getVal (input [i]);

        for ( i = findBase(); i <= 62; i++ ) {
            if ( sum % (i - 1) == 0 ) {
                printf ("%d\n", i);
                baseFound = 1;
                break;
            }
        }

        if ( baseFound==0 )
            printf ("such number is impossible!\n");
    }

    return 0;
}
Exemple #22
0
void Leaf::getInstruction(std::vector<instruction_set> *instruction_list){
	instruction_set instruction;
	instruction.id_motor = getId();
	instruction.value = getVal();
	instruction.speed = getSpeed();
	instruction_list->push_back(instruction);
}
Exemple #23
0
//---	summerize	---
	void FFT2vector(const std::vector< Tyfft_ >& rawdata, size_t freq_point_num, FFTwindow window, double rate_){
		rate = rate_;
		size_t size2Power = getPower2Num(freq_point_num);
		size_t time_point_num = size2Power/2;
		size_t time_slice_num = (size_t)floor(rawdata.size()/time_point_num);	//	number of time slice
		fft_timing.resize(time_slice_num);
		Power.resize(time_slice_num);
		double* src_x = new double[size2Power];
		double* amp_x = new double[size2Power];
		for(size_t t=0; t<rawdata.size(); t+=time_point_num){	//	time slice
			double t_avg=0.0;
			for(size_t i=0; i<size2Power; i++){
				src_x[i] = getVal(rawdata[t+i]);
				t_avg += getTime(i);
			}
			// fft
			FFT2(src_x, size2Power, window);
			FFT2Power(amp_x, src_x, size2Power);
			Power[t]=(Pointer2Stdv(amp_x, size2Power/2);
			//time
			fft_timing[t] = t_avg/size2Power;
		}
		//	frequency
		frequency.resize(size2Power/2);
		for(size_t i=0; i<size2Power/2; i++) frequency[i] = rate*i/size2Power;
		delete[] src_x;
		delete[] amp_x;
	}
 TreeNode* recover(const string& s, int& i, int depth) {    
   const int d = getD(s, i);
   if (d != depth) { i -= d; return nullptr; }    
   auto root = new TreeNode(getVal(s, i));
   root->left = recover(s, i, d + 1);    
   root->right = recover(s, i, d + 1);
   return root;
 }
Exemple #25
0
int main(void){
	int T;
	char c;
	scanf("%d",&T);
	unit['I'] = 'A'; unit['P'] = 'W'; unit['U'] = 'V';
	for(int pnum = 0; pnum < T; ){
		def['I'] = def['P'] = def['U'] = 0;
		getVal();
		getVal();
		if(def['I']){
			if(def['P']) c = 'U', val = P/I;
			else 		 c = 'P', val = I*U;
		} else c = 'I', val = P/U;
		printf("Problem #%d\n%c=%.2lf%c\n\n",++pnum,c,val,unit[c]);
	}
	return 0;
}
// OneMax
double Chromosome::oneMax () const {

    double result = 0;

    for (int i = 0; i < length; ++i)
        result += getVal(i);

    return result;
}
Exemple #27
0
 DiscreteValueVect DiscreteValueVect::operator~() const {
   DiscreteValueVect ans(d_type,d_length);
   unsigned int maxVal = (1<<d_bitsPerVal) - 1;
   for(unsigned int i=0;i<d_length;++i){
     unsigned int v1=getVal(i);
     ans.setVal(i,maxVal-v1);
   }
   return(ans);
 };
Exemple #28
0
int findBase ()
{
    char maxi = '1';
    int i;
    for ( i = 0; i < len_input; i++ )
        if ( maxi < input [i] ) maxi = input [i];

    return getVal (maxi) + 1;
}
Exemple #29
0
void CIniFile::readInfo(void)
{
    m_lstNodeInfo.clear();

    std::fstream inStream(m_strFile.c_str(), std::ios::in);
    if (!inStream.good())
    {
        Q_Printf("open file %s error.", m_strFile.c_str());
        inStream.close();

        return;
    }

    char pBuffer[Q_ONEK];
    std::string strTmp;
    std::string strNode;

    while(inStream.good())
    {
        Q_Zero(pBuffer, sizeof(pBuffer));

        inStream.getline(pBuffer, (std::streamsize)(sizeof(pBuffer) - 1));

        strTmp = std::string(pBuffer);
        strTmp = Q_Trim(strTmp);
        if (strTmp.empty()
            || isNote(strTmp))
        {
            continue;
        }

        //去掉注释
        removeNote(strTmp);
        strTmp = Q_Trim(strTmp);
        if (strTmp.empty())
        {
            continue;
        }

        if (isNode(strTmp))
        {
            strNode = getNode(strTmp);

            continue;
        }

        if (isKey(strTmp))
        {
            setStringValue(strNode.c_str(), getKey(strTmp).c_str(), getVal(strTmp).c_str());
        }
    }

    inStream.close();

    return;
}
Exemple #30
0
    void read() {
        QFile f("/etc/mpd.conf");

        if (f.open(QIODevice::ReadOnly|QIODevice::Text)) {
            int details=0;
            while (!f.atEnd()) {
                QString line = QString::fromUtf8(f.readLine()).trimmed();
                if (line.startsWith('#')) {
                    continue;
                } else if (!(details&DT_DIR) && line.startsWith(QLatin1String("music_directory"))) {
                    QString val=getVal(line);
                    if (!val.isEmpty() && QDir(val).exists()) {
                        dir=Utils::fixPath(val);
                        details|=DT_DIR;
                    }
                } else if (!(details&DT_ADDR) && line.startsWith(QLatin1String("bind_to_address"))) {
                    QString val=getVal(line);
                    if (!val.isEmpty() && val!=QLatin1String("any")) {
                        host=val;
                        details|=DT_ADDR;
                    }
                } else if (!(details&DT_PORT) && line.startsWith(QLatin1String("port"))) {
                    int val=getVal(line).toInt();
                    if (val>0) {
                        port=val;
                        details|=DT_PORT;
                    }
                } else if (!(details&DT_PASSWD) && line.startsWith(QLatin1String("password"))) {
                    QString val=getVal(line);
                    if (!val.isEmpty()) {
                        QStringList parts=val.split('@');
                        if (!parts.isEmpty()) {
                            passwd=parts[0];
                            details|=DT_PASSWD;
                        }
                    }
                }
                if (details==DT_ALL) {
                    break;
                }
            }
        }
    }