Exemplo n.º 1
0
void printOneLineTX(char *lineStr, char *s){
	int dig;
	int iStart, iStop;
	char numL[20];
	sprintf(s, "%s{\n",s);
	switch(ticketTypeInt){
	case 1:
	case 2:
	case 3:
	case 4:
	case 7:
	case 8:
		sprintf(s, "%s \"amount\":null,\n",s);
		sprintf(s, "%s \"numbers\": [\n",s);
		dig = 0;iStart = -1; iStop = -1;
		while(1){
			if(getNextNum(lineStr, dig, &iStart, &iStop)<0) break;
			copyNum(lineStr, numL, iStart, iStop);
			if(dig>0)
				sprintf(s, "%s,\n",s);
			sprintf(s, "%s %s",s,numL);
			dig++;
		}
        if(dig==0) sprintf(s, "%s null",s);
		sprintf(s, "%s\n ],\n",s);
		sprintf(s, "%s \"lineType\":null,\n",s);
		sprintf(s, "%s \"sumitUp\":null,\n",s);
		sprintf(s, "%s \"sumAmount\":null\n",s);
		break;
	}
	sprintf(s, "%s}",s);
}
Exemplo n.º 2
0
// Parses a JSON schedule into the global variable
// schedule and sorts it
void scheduleParse(void) {
    char key[11];
    enum key_t i;
    unsigned long value, current_zone;
    while(RxFifo_Size() > 0) {
        if(!getNextString(key))
            break;
        for(i = ZONE; i < (sizeof(KEYS)/sizeof(char*)); i++) {
            if(!strcmp(key, KEYS[i])) {
                if(!getNextNum(&value)) 
                    break;
                switch(i) {
                    case ZONE:
                        current_zone = value;
                        break;
                    case START:
                        schedule[schedule_idx].zone = current_zone;
                        schedule[schedule_idx].start_time = value;
                        break;
                    case END:
                        schedule[schedule_idx].end_time = value;
                        schedule_idx++;
                        break;
                    default:
                        break;
                }
            }
        }
    }
}
Exemplo n.º 3
0
int
getPathSize(int num)
{
	int count = 0;
	int tempResult = 0;

	array[1] = 1;
	if(array[num] != 0)
	{
		//printf("first find! %d:%d\n", num , array[num]);
		return array[num];
	}
	
	tempResult = num;
	arrayTemp[count] = tempResult;
//	count = 1;
	while(1)
	{
		tempResult = getNextNum(tempResult);
		//printf("[%d] tempResult %d\n", count, tempResult);
		count++;		

		if(tempResult > 1000000)
		{
			//printf("over 1,000,000! %d \n", tempResult);
			arrayTemp[count] = 0;
			continue;
		}
		if(array[tempResult] != 0)
		{
			int x = 0;
			int index = 0;
			int i = 0;
			//save previous path
			x = array[tempResult];
			//printf("middle x %d index %d\n", x , tempResult);
			for(i=0; i<count; i++)
			{
				index = arrayTemp[i];
				
				array[index] = x + count - i;
				//printf("array[%d] = %d\n", index, x+count-i);
				arrayTemp[i] = 0;
			}
			return array[num];
		}		
		arrayTemp[count] = tempResult; 
	}	
}
Exemplo n.º 4
0
void main(void)
{
    char number;
    TRISBbits.RB4 = 0;
    initialiseNumPad();
    INTCONbits.GIE = 1;
    INTCONbits.PEIE = 0;
    RCONbits.IPEN = 1;

    while(1)
    {
        number = getNextNum();
        /*Use debugger to look at number and np_buffer.*/
    }
}
Exemplo n.º 5
0
void printOneLineSumitUpTX(char *lineStr, char *s, char *sumitUpLine, int sumitUpFlg){
	int dig;
	int iStart, iStop;
	char numL[20];

	sprintf(s, "%s{\n",s);
	switch(ticketTypeInt){
	   case 5:
	   case 6:
		{ char amount[10];
		   int lineType, sumitUp;
		    getAmmountFromLineTX(lineStr, amount);
			sprintf(s, "%s \"amount\": \"%s\",\n",s, amount);
			sprintf(s, "%s \"numbers\": [\n",s);
			dig = 0;iStart = -1; iStop = -1;
			while(1){
				if(getNextNum(lineStr, dig, &iStart, &iStop)<0) break;
				copyNum(lineStr, numL, iStart, iStop);
				if(dig>0)
					sprintf(s, "%s,\n",s);
				sprintf(s, "%s %s",s,numL);
				dig++;
			}
	        if(dig==0) sprintf(s, "%s null",s);
			sprintf(s, "%s\n ],\n",s);
			lineType = getLineTypeTX(lineStr);
			sprintf(s, "%s \"lineType\": %d,\n",s, lineType);
			if(sumitUpFlg == 0){
			   sprintf(s, "%s \"sumitUp\":null,\n",s);
			   sprintf(s, "%s \"sumAmount\":null\n",s);
			}else{
				sumitUp = getSumitUpTX(sumitUpLine, amount);
				   sprintf(s, "%s \"sumitUp\": %d,\n",s, sumitUp);
				   sprintf(s, "%s \"sumAmount\": \"%s\"\n",s, amount);

			}
		}

		   break;
	}
	sprintf(s, "%s}",s);
}
Exemplo n.º 6
0
int
findLongestNum(int startNum, int endNum)
{
	int result = 0;
	int tempResult = 0;
	int i = 0;
	int j = 0;
	int count = 0;

	for(i = startNum; i<=endNum; i++)
	{
		tempResult = i;
		count = 1;
		while (1)
		{
			if(tempResult == 1)
				break;
			tempResult = getNextNum(tempResult);
			count++;
			printf("[%d:%d] tempResult %d\n", i, count,  tempResult); 
			if(tempResult == 1)
			{
				break;
			}			
		}
		if(result < count)
		{
			result = count;
		}


		printf("%d %d \n", i, count);


	}

	return result;
}
Exemplo n.º 7
0
Polynom::Polynom(const string str)
{
   int tmp, tmp1, tmp2;

   coefficients.clear();
   if (str.length() < 8)
	   throw(invalid_argument("incorrect number input. You can try help\n"));

   for (auto i = 0; i < str.length(); i++)
	  if (!isdigit(str[i]) && str[i] != 'x' && str[i] != '^' && str[i] != '+' && str[i] != '-' && str[i] != '/' && str[i] != '(' && str[i] != ')')
		  throw(invalid_argument("incorrect number input. You can try help\n"));
	 
   tmp = 0;
   if (str[0] == '-' || str[0] == '+')
	  tmp++;

   do
   {
	  tmp1 = str.find("(", tmp);
	  if (tmp1 != tmp)
		  throw(invalid_argument("incorrect number input. You can try help\n"));

	  tmp = ++tmp1;
	  while (tmp < str.size() && isdigit(str[tmp]))
		 tmp++;
	  if (tmp == tmp1)
		  throw(invalid_argument("incorrect number input. You can try help\n"));

	  if (tmp != -1)
	  {
		 tmp1 = str.find("/", tmp);
		 if (tmp1 == -1 || (tmp1 - tmp) != 0)
			 throw(invalid_argument("incorrect number input. You can try help\n"));

		 tmp = ++tmp1;
		 while (tmp < str.size() && isdigit(str[tmp]))
			tmp++;
		 if (tmp == tmp1)
			 throw(invalid_argument("incorrect number input. You can try help\n"));

		 tmp1 = str.find(")", tmp);
		 if (tmp1 == -1 || (tmp1 - tmp) != 0)
			 throw(invalid_argument("incorrect number input. You can try help\n"));

		 tmp = ++tmp1;
		 tmp1 = str.find("x^", tmp);
		 if (tmp1 == -1 || (tmp1 - tmp) != 0)
			 throw(invalid_argument("incorrect number input. You can try help\n"));

		 tmp1 += 2;
		 while (tmp1 < str.size() && isdigit(str[tmp1]))
			tmp1++;

		 if (tmp == tmp1)
			 throw(invalid_argument("incorrect number input. You can try help\n"));

		 if (tmp1 == str.size())
			break;

		 tmp2 = tmp = tmp1;
		 tmp = str.find("+", tmp);
		 tmp1 = str.find("-", tmp1);
		 if (tmp == -1 && tmp1 == -1)
			 throw(invalid_argument("incorrect number input. You can try help\n"));
		 
		 if (tmp == -1)
			tmp = tmp1;

		 if (tmp1 < tmp)
			tmp = tmp1;

		 if ((tmp - tmp2) != 0)
			 throw(invalid_argument("incorrect number input. You can try help\n"));
		 tmp++;
	  }
	  else
		  throw(invalid_argument("incorrect number input. You can try help\n"));
   }
   while (true);

   MegaNatural lastCoef,b_lastCoef;
   int sign;
   MegaRational coef();
   bool first = true;
   int pos = 0;
   
   do
   {
	  if (first)
	  {
		 first = false;
		 if (str[0] == '-')
			sign = -1;
		 else
			sign = 1;

		 MegaInteger numerator(getNextNum(str, pos));
		 numerator = numerator*(MegaInteger)(-1);
		 MegaNatural denominator(getNextNum(str, pos));
		 coefficients.push_front(MegaRational(numerator, denominator));
		 lastCoef = getNextNum(str, pos);
		 continue;
	  }
	  tmp = str.find("+", pos);
	  tmp1 = str.find("-", pos);
	  if (tmp == -1 && tmp1 == -1)
		 break;

	  if (tmp != -1 && tmp1 != -1)
		 if (tmp < tmp1)
			sign = 1;
		 else
			sign = -1;

	  if (tmp == -1)
		 sign = -1;

	  if (tmp1 == -1)
		 sign = 1;

	  MegaInteger numerator(getNextNum(str, pos));
	  numerator = numerator*(MegaInteger) (-1);
	  MegaNatural denominator(getNextNum(str, pos));
	  coefficients.push_front(MegaRational(numerator, denominator));

	  b_lastCoef = lastCoef;
	  lastCoef = getNextNum(str, pos);
	  if (lastCoef >= b_lastCoef)
	  {
		 coefficients.clear();
		 coefficients.resize(0);
		 throw(invalid_argument("incorrect number input. You can try help\n"));
	  } 
	  else
	  {
		 while ((b_lastCoef - (MegaNatural) 1) > lastCoef)
		 {
			b_lastCoef = b_lastCoef - (MegaNatural) 1;
			coefficients.push_front(MegaRational());
		 }
	  }
   }
   while (pos < str.size());
   while (lastCoef>(MegaNatural)0)
   {
	   lastCoef = lastCoef - (MegaNatural)1;
	   coefficients.push_front(MegaRational());

   }
}