示例#1
0
main(){
	unsigned short base = 1;
	unsigned short power = 1;
	unsigned short menuAnswer = 0;
	int userInput = 0;

	menuAnswer = powerMenu();
	while (menuAnswer != 4){//while the user has not selected "Exit Program"
		if (menuAnswer == 1){//if user selects change base
			printf("Please enter a base between 1 and 25:");
			userInput = getNum();
			if (checkRange(userInput, kBaseMax, kMinNum)){
				base = userInput;
			}
		}
		else if (menuAnswer == 2){//if user selects change exponant
			printf("Please enter a exponent between 1 and 5:");
			userInput = getNum();
			if (checkRange(userInput, kPowerMax, kMinNum)){
				power = userInput;
			}
		}
		else if (menuAnswer == 3){//if user selects "Display base raised to exponents"
			printf("%d to the power %d = %d", base, power, calculation(base, power));
		}
		menuAnswer = powerMenu();//Get menu selection from user
	}
	return 0;
}
示例#2
0
int main()
{
	long long int num;
	scanf("%lld",&num);
	num = positive(num);

	int i = 0;
	while(i < getSize(num))
	{
		int tmp = getNum(num,getSize(num) - (i++) - 1);
		printf("%d : ", tmp);
		int j = 0;
		int cnt = 0;
		while(j < getSize(num))
		{
			if(getNum(num,getSize(num) - j - 1) == tmp)
			{
			cnt++;
			}
			j++;	
		}
		printf("%d\n",cnt);
	}	
	
	return 0;
}
示例#3
0
int main(void)
{
    int t = 0, n = 0, i = 0, mode = 0, num;
    const static int LEN = 100000;
    int arr[LEN];
    scanf("%d", &t);
    while(t--)
    {
        mode = 0;
        memset(arr, 0, LEN * sizeof(int));
        n = getNum();
        i = n;
        for(i = 0; i < n; ++i)
        {
            num = getNum() - 1;
            arr[num]++;
            if (arr[num] > mode)
                mode = arr[num];
        }
        
        printf("%d\n", n - mode);
    }
    
	return 0;
}
int main(){

    char str[1001];
    int x[1000], c[1000];

    while (gets(str))
    {
        int count = getNum(str, c);
        gets(str);
        int set = getNum(str, x);

        int exp, sum, i, j;

        for (j = 0; j < set; j++)
        {
            sum = 0;
            exp = 1;
            for (i = count - 1; i >= 0; i--, exp *= x[j])
                sum += c[i] * exp;
            printf("%d%c", sum, j == set - 1 ? '\n' : ' ');
        }

    }

    return 0;
}
示例#5
0
文件: funcpoint.c 项目: sin90lzc/my_c
/**
 *
 * main接受一个参数,如果参数比0大,则执行getNum(getMax,...),否则执行getNum(getMin,...)。
 */
int main(int argc,char ** argv){
	extern int getNum(int (*)(int,int),int,int);
	extern int getMax(int,int);
	extern int getMin(int,int);
	extern int strcmp(const char *,const char *);

	//printf("%d\n",argc);	
	
	if(argc!=2){
		fprintf(stderr,"error:need a number parameter!\n");
		return 1;
	}
	
	char * p=*(argv+1);

	int result=0;

	printf("%s\n",p);
	
	if(strcmp(p,"0")){
		result=getNum(getMax,3,5);
	}else{
		result=getNum(getMin,3,5);
	}

	printf("result=%d\n",result);
		
	return 0;
}
int main(){
	//menu
	printf("Enter the operation of your choice:\n");
	printf("a.add\t\ts.subtract\nm.multiply\td.divide\nq.quit\n");
	//choice
AGAIN:
	fflush(stdin);
	char choice = getchar();
	
	switch (choice)
	{
		case 'a':
			getNum(add,0);
			goto AGAIN;
		case 's':
			getNum(subtract,0);
			goto AGAIN;
		case 'm':
			getNum(multiply,0);
			goto AGAIN;
		case 'd':
			getNum(divide,1);
			goto AGAIN;
		case 'q':
			break;
		default:
			printf("Try to select a correct selection!\n");
			goto AGAIN;
	}
	printf("Bye.\n");
	system("pause");
	return 0;
}
void
SbXipMarkerShapes::getVertices(int index, SoMFVec3f &vertices)
{
	if ((index < 0) || (index > getNum()))
		index = getNum();

	vertices.set(mShapes[index][1]);
}
void 
SbXipMarkerShapes::getNumVertices(int index, SoMFInt32 &numVertices)
{
	if ((index < 0) || (index > getNum()))
		index = getNum();

	numVertices.set(mShapes[index][2]);
}
const char* 
SbXipMarkerShapes::getName(int index)
{
	if ((index < 0) || (index > getNum()))
		index = getNum();

	return (mShapes[index][0]);
}
示例#10
0
文件: addSubDiv.c 项目: HoboJ/avr
int main(int argc, char *argv[])
{
    char choice;
    int num1, num2;
    float div;
    int result, dummyRead;

    while ( 1 && choice != '5' )
    {

    printf("Choose what to do with the numbers input: \n");
    printf("1. Add \n");
    printf("2. Subtract \n");
    printf("3. Multiply \n");
    printf("4. Divide \n");
    printf("5. Quit \n\n");

    choice = getchar();

    dummyRead = getchar();

    if ( choice != '5' )
    {
        num1 = getNum ();
        num2 = getNum ();
    }

    switch ( choice )
    {
        case '1':
            result = add ( num1, num2 );
            break;
        case '2':
            result = subtract ( num1, num2 );
            break;
        case '3':
            result = multiply ( num1, num2 );
            break;
        case '4':
            div = divide ( num1, num2 );
            break;
    }

    if ( choice == '4' )
        printf ( "\n\nThe result is, %f \n\n", div );
    else if ( choice == '5' )
        printf ( "Goodbye.\n\n" );
    else
        printf ( "The result is, %d \n\n", result );

    }

    //system ( "pause" );

    return 0;
}
示例#11
0
std::string eServiceReference::toCompareString() const
{
	std::string ret;
	ret += getNum(type);
	ret += ":0";
	for (unsigned int i=0; i<sizeof(data)/sizeof(*data); ++i)
		ret+=":"+getNum(data[i], 0x10);
	ret+=":"+encode(path);
	return ret;
}
示例#12
0
文件: main.cpp 项目: linmx0130/OJCode
	void Init()
	{
		for (int i=1;i<=n;++i)
		{
			for (int j=1;j<=m;++j)
			{
				Set[getNum(i,j)]=getNum(i,j);
			}
		}
	}
int main(int argc , char **argv)
{
	if(argc>1 && strcmp(argv[1],"DEBUG")==0) debug=1;
	int t;scanf("%d",&t);
	int a,b;
	while(t--){
		scanf("%d %d",&a,&b);
		printf("%d\n",(getNum(b) - getNum(a-1)+MOD)%MOD);
	}
	return 0;
}
示例#14
0
main()
{
	n = 0;
	int i, j; double theta1, phi1, theta2, phi2, d, D;
	double x1, y1, z1, x2, y2, z2;
	char s[34], t[34];
	while (1)
	{
		cin >> s;
		if (s[0] == '#')
			break;
		for (i = 0; i < strlen(s); i++)
			names[n][i] = s[i];
		nameL[n] = strlen(s);
		cin >> lat[n] >> lon[n];
		n++;
	}
	while (1)
	{
		cin >> s;
		if (s[0] == '#')
			break;
		cin >> t;
		cout << s << " - " << t << endl;
		i = getNum(s);
		j = getNum(t);
		if (i == n || j == n)
			cout << "Unknown" << endl;
		else
		{
			theta1 = lon[i] / 180 * PI + PI;
			theta2 = lon[j] / 180 * PI + PI;
			phi1 = (90 - lat[i]) / 180 * PI;
			phi2 = (90 - lat[j]) / 180 * PI;
			x1 = R*sin(phi1)*cos(theta1);
			x2 = R*sin(phi2)*cos(theta2);
			y1 = R*sin(phi1)*sin(theta1);
			y2 = R*sin(phi2)*sin(theta2);
			z1 = R*cos(phi1);
			z2 = R*cos(phi2);
			d = sqrt((x1 - x2)*(x1 - x2) +
						(y1 - y2)*(y1 - y2) +
						(z1 - z2)*(z1 - z2));
			D = R*2*asin(d/(2*R));
			if (D - int(D) >= D + 1 - int(D))
				D++;

			cout << int(D) << " km" << endl;
		}
	}

	return 0;
}
示例#15
0
std::string eServiceReference::toString() const
{
	std::string ret;
	ret += getNum(type);
	ret += ":";
	ret += getNum(flags);
	for (unsigned int i=0; i<sizeof(data)/sizeof(*data); ++i)
		ret+=":"+ getNum(data[i], 0x10);
	ret+=":"+encode(path); /* we absolutely have a problem when the path contains a ':' (for example: http://). we need an encoding here. */
	if (name.length())
		ret+=":"+encode(name);
	return ret;
}
示例#16
0
bool isPalindrome(int x) {
    if (x < 0)  return false;

    int len = getLength(x);
    for (int i = 0; i < len / 2; ++i) {
        int a = getNum(i, x);
        int b = getNum(len - 1 - i, x);
        
        if (a != b) return false;
    }
    
    return true;
}
static int line2DeductionNoAdjEvent(char *line,EVENT_INTERFACE *pEvent)
{
	struct tm tm_A;
	time64_t time64A;
	long double ratio;
	
	memset(&tm_A,'\0',sizeof(tm_A));
	tm_A.tm_year=getNum(line,4)-1900;
	tm_A.tm_mon=getNum(line+4,2)-1;
	tm_A.tm_mday=global_debt.deductionPerMonDay;
	time64A=mktime64(&tm_A);
	sscanf(strstr(line,",")+1,"%Lf",&ratio);
	event_class_deduction_no_adjust_init(pEvent,time64A,global_debt.deductionPerMonAmount,ratio);
	return 0;
}
int main()
{
    int n;

    while (n = getNum())
    {
        for (int i = 0; i < n; i++)
            num[i] = getNum();
        long long ans = 0;
        merge_sort(0, n - 1, ans);
        printf("%lld\n", ans);
    }

    return 0;
}
示例#19
0
static int line2IntrEvent(char *line,EVENT_INTERFACE *pEvent)
{
	struct tm tm_A;
	time64_t time64A;
	long double intr;
	
	memset(&tm_A,'\0',sizeof(tm_A));
	tm_A.tm_year=getNum(line,4)-1900;
	tm_A.tm_mon=getNum(line+4,2)-1;
	tm_A.tm_mday=getNum(line+6,2);
	time64A=mktime64(&tm_A);
	sscanf(strstr(line,",")+1,"%Lf",&intr);
	event_class_adjust_intr_init(pEvent,time64A,intr);
	return 0;
}
示例#20
0
文件: 2516.c 项目: UsuallyGO/POJ
int main()
{
    int num;
    char c;

    srand((unsigned int)time(0));
    root = NULL;
    while(1)
    {
	printf("0 means finish:");
	scanf("%c", &c);
	if(c == '0')
	    break;

	num = getNum();
	printf("Get num :%d\n", num);
        TreapAdd(num);
	printf("Display trees:\n");
	ShowPre();
	printf("\n");
//	fflush(stdin);
	getchar();
    }

    return 0;
}
示例#21
0
Local void countIt(struct LOC_scanMusic *LINK)
{
  struct LOC_countIt V;

  V.LINK = LINK;
  if (LINK->ngrace > 0) {
    LINK->ngrace--;
    return;
  }
  if (LINK->nmulti > 0) {
    decmulti(LINK);
    return;
  }
  if (LINK->count % 3 != 0 &&
      (LINK->note[0] != rest && note_attrib[LINK->voice-1]['d' - 'a'] ||
       LINK->note[0] == rest && rest_attrib[LINK->voice-1]['d' - 'a']))
    LINK->count += LINK->count / 2;
/* p2c: mtx.pas, line 150:
 * Note: Using % for possibly-negative arguments [317] */
  incbar(LINK->count, &V);
  LINK->l = pos1(multi_group, LINK->note);
  if (LINK->l <= 0)
    return;
  predelete(LINK->note, LINK->l);
  getNum(LINK->note, &LINK->nmulti);
  decmulti(LINK);
}
示例#22
0
void pc_record_type::takeItem(short which_item)
//short pc_num,which_item;  // if which_item > 30, don't update stat win, item is which_item - 30
{
	int i;
	bool do_print = true;

	if (which_item >= 30) {
		do_print = false;
		which_item -= 30;
		}

	if ((weap_poisoned == which_item) && (status[STATUS_POISONED_WEAPON] > 0)) {
			add_string_to_buf("  Poison lost.           ");
			status[STATUS_POISONED_WEAPON] = 0;
		}

	if ((weap_poisoned > which_item) && (status[STATUS_POISONED_WEAPON] > 0))
		weap_poisoned--;

	for (i = which_item; i < 23; i++) {
		items[i] = items[i + 1];
		equip[i] = equip[i + 1];
		}
	items[23] = return_dummy_item();
	equip[23] = false;

	if ((stat_window == getNum()) && (do_print))
		put_item_screen(stat_window,1);
}
示例#23
0
Static void setSize(Char *line_)
{
  Char line[256];
  stave_index0 i = 0;
  Char word[256];
  stave_index0 FORLIM;

  strcpy(line, line_);
  while (i < ninstr) {
    GetNextWord(word, line, blank_, dummy);
    if (*word == '\0')
      break;
    i++;
    getNum(word, &musicsize);
    stave_size[i-1] = musicsize;
  }
  if ((unsigned)musicsize >= 32 || ((1L << musicsize) & 0x110000L) == 0) {
    FORLIM = ninstr;
    for (i = 0; i <= FORLIM - 1; i++) {
      if (stave_size[i] == unspec)
	stave_size[i] = musicsize;
    }
  }
  if (musicsize < 16)
    musicsize = 16;
  else if (musicsize > 20)
    musicsize = 20;
}
int main()
{
    int n, i, missle[N], lis[N];
    char str[10];
    bool first = true;

    scanf("%d", &n);
    getchar();
    getchar();

    while (n--)
    {
        if (first)
            first = false;
        else
            putchar('\n');
        i = 0;
        while (gets(str) && str[0])
            missle[i++] = getNum(str);

        int len = LIS(missle, i, lis);
        printf("Max hits: %d\n", len);
        for (i = 0; i < len; i++)
            printf("%d\n", lis[i]);
    }

    return 0;
}
示例#25
0
void setOnly(Char *line_)
{
  Char line[256];
  short num, num1, num2, l;
  Char s[256];
  Char STR1[256];

  strcpy(line, line_);
  if (*line == '\0')
    return;
  if (startsWithIgnoreCase(line, "only"))
    GetNextWord(STR1, line, colon_, dummy);
  for (l = 0; l <= lines_in_paragraph - 1; l++)
    omit_line[l] = true;
  do {
    GetNextWord(s, line, blank_, comma_);
    if (*s == '\0')
      return;
    curtail(s, comma_);
    if (pos1('-', s) == 0) {
      getNum(s, &num);
      if (num > 0 && num <= lines_in_paragraph)
	omit_line[num-1] = false;
      else
	warning("Invalid line number in Only: is skipped", print);
    } else {
      getTwoNums(s, &num1, &num2);
      if (num1 > 0 && num2 <= lines_in_paragraph) {
	for (num = num1 - 1; num <= num2 - 1; num++)
	  omit_line[num] = false;
      } else
	warning("Invalid line range in Only: is skipped", print);
    }
  } while (true);
}
示例#26
0
 static Value getValue(JsonStream& stream)
 {
     int c = stream.skipSpaces();
     if (c == EOF)
     {
         return Value();
     }
     else if (c == '[')  // 数组
     {
         stream.get();
         return getArray(stream);
     }
     else if (c == '{')  // 字典
     {
         stream.get();
         return getDict(stream);
     }
     else if (is_number(c))  // 数字
     {
         return getNum(stream);
     }
     else if (c == '\"')  // 字符串
     {
         stream.get();
         auto str = getString(stream);
         return Value(str);
     }
     return Value();
 }
void getData(char *buf, int *nNum, int num[], int *nStr, char str[][20])
{
	int k;
	k = 0;

	
	while((buf[k] != '\0') && (buf[k] != '\n'))
	{
		while(buf[k] == ' ' || buf[k] == '\t')
		(k)++;
		
		if(isdigit(buf[k]) || buf[k] == '-')
			/* 填写调用getNum函数,获取整型数的语句		*/
		{
			getNum( buf, k, num );
			*nNum += 1;
			num[*nNum + 1] = *num;
		}

		if(isalpha(buf[k]))
			/* 填写调用getStr函数,获取字符串的语句		*/
		{
			getStr( buf, k, *str );
			*nStr += 1;
			strcpy(str[*nStr+1],*str);
		}
		while(buf[k] != ' ' && buf[k] != '\t' && buf[k] != '\0' && buf[k] != '\n')
			(k)++;
	}
}
示例#28
0
qdbbot::bashQuote* qdbbot::parseQuote(std::stringstream* src)
{
	//std::cout << src->str() << std::endl << "there it was again" << std::endl;
///	std::cout << "qdbbot: allocating quote" << std::endl;
	qdbbot::bashQuote* quote = new qdbbot::bashQuote();
	while(!src->eof())
	{

		std::string line;
		std::getline(*src, line, '\n');
		if(src->bad()){};
			//try to fail gracefully
			//
		size_t loc = line.find("span class=qt"); 

		if(loc != std::string::npos)
		{
			std::cout << "qdbbot: bashline: " <<line << std::endl;

			quote->num = getNum(line);
			std::string tmp = getInitialLine(line);
			std::cout << "qdbbot: trimed line is: " << tmp << std::endl;
			quote->lines.push_back(tmp);
			
			if(line.find("</span>", loc) != std::string::npos)
			{
				std::cout << "qdbbot: number of lines: " << quote->lines.size() << std::endl;
				return quote;
			}
		}
		else if(quote->lines.size() > 0)
		{
			if(line.find("</span>") != std::string::npos)
			{

				std::string tmp = trimBodyLine(line);
				std::cout << "qdbbot: trimed line is: " << tmp << std::endl;
				quote->lines.push_back(tmp);
				std::cout << "qdbbot: number of lines: " << quote->lines.size() << std::endl;
				std::cout << "qdbbot: last bashline: " <<line << std::endl;
				return quote;
			}
			//quote->lines.push_back(trimBodyLine(line));
			std::string tmp = trimBodyLine(line);
			std::cout << "qdbbot: trimed line is: " << tmp << std::endl;
			quote->lines.push_back(tmp);
//			std::cout << "qdbbot: bashline: " <<line << std::endl;
		}



	}

	if(quote->lines.size() < 1){
		delete quote;
		quote = NULL;
	}
	return quote;

}
示例#29
0
std::vector<std::string> qdbbot::getBashNums(std::stringstream& src)
{
	std::vector<std::string> nums;
	std::cout << "qdbbot::getBashNums: entering loop" << std::endl;
	while(!src.eof())
	{
		//char* buf = new char[GLBUFFERSIZE];
		//src.getline(buf, GLBUFFERSIZE);
	
		std::string line;
		std::getline(src, line, '\n');

		if(src.bad()){}
			//try to fail gracefully

		//delete buf;


		if(line.find("<span class=qt") != std::string::npos)
		{
			std::cout << "qdbbot::getBashNums: found a num" << std::endl;
			nums.push_back(getNum(line));
		}
	}

	std::cout << "basbot::getBashNums: finished parseing nums" << std::endl;
	return nums;
}
/*---------------------------------------------------------------------*//**
	スロットを作成 ⇒ js_AllocSlot
**//*---------------------------------------------------------------------*/
bool EsObjectSlots::create()
{
	EsScope* scope = _objParentRef->getScope();
	const EsClass* cls = _objParentRef->getClass();

	u16 numReservedSlot;
	if(cls->getAdditionalReservedSlotNum(&numReservedSlot, _objParentRef))
	{
		if(scope->getFreeSlotIndex() == cls->getFreeSlotIndex())
		{
			scope->setFreeSlotIndex(scope->getFreeSlotIndex() + numReservedSlot);
		}
	}

	if(scope->getFreeSlotIndex() >= getNum())
	{
		if(!recreate(scope->getFreeSlotIndex() + 1))
		{
			return false;
		}
	}

	ASSERT(getValue(scope->getFreeSlotIndex())->isVoid());
	scope->setFreeSlotIndex(scope->getFreeSlotIndex() + 1);
	return true;
}