int agregaBombas(/*int nbombas*/){ int i,x,y;// contador de bombas printf(YELLOW "Numero de bombas: "); int nbombas = getnum(); int seeder = 0; printf(RED "%d\n", nbombas); x = random(FILAS, 1); y = random(COLUMNAS, 2); for (i = 1; i <= nbombas; i++) { campo[x][y] = BOMBA; x = random(FILAS, i+1+seeder); y = random(FILAS, i+4+seeder); for (int x2 = 0, p = 0; x2 < 9; x2++) { for (int y2 = 0; y2 < 9; y2++) { if (campo[x2][y2] == BOMBA) { p++; } } if (p < i && x2 == 8) { seeder++; i--; } } } return nbombas; }
/* ** Read an integer numeral and raises an error if it is larger ** than the maximum size for integers. */ static int getnumlimit (Header *h, const char **fmt, int df) { int sz = getnum(fmt, df); if (sz > MAXINTSIZE || sz <= 0) return luaL_error(h->L, "integral size (%d) out of limits [1,%d]", sz, MAXINTSIZE); return sz; }
// Delete a screen. Return status. int deleteScreen(Value *rp,int n) { EScreen *scrp; // Get the number of the screen to delete. if(n == INT_MIN && !getnum(text243,&n)) // "Delete screen" return rc.status; // Make sure it exists. if(!sfind((ushort) n,NULL,&scrp)) return rcset(FAILURE,0,text240,n); // "No such screen '%d'" // It can't be current. if(scrp == cursp) return rcset(FAILURE,0,text241); // "Screen is being displayed" // Everything's cool ... nuke it. if(unlistscreen(scrp) != SUCCESS) return rc.status; freescreen(scrp); return rcset(SUCCESS,0,text178,n); // "Deleted screen %d" }
int main(){ int i,j,k; cout << " Please give lay lad sen "; cin >> i >>j >>k; cout << " Number is " <<getnum(i-1,j-1,k-1)<<endl; return 0; }
void wait(student s[], int *cur) // 等待用户操作函数 { char str[10]; int op; while (1) { memset(str, 0, 10*sizeof(char)); fflush(stdin); scanf("%8s", str); fflush(stdin); op = getnum(str); if (op>=1 && op<=6) { switch (op) { case 1 : input(s, cur); break; // 输入 case 2 : insert(s, cur); break; // 插入 case 3 : sort(s, cur); break; // 排序 case 4 : find(s, *cur); break; // 查找 case 5 : del(s, cur); break; // 删除 case 6 : output(s, cur); break; // 输出 } } else if (op == -2) exit(0); else printf("XXX 输入错误,请重新输入:"); } }
void dfs(int x,int y){ //定义一个行走方向的数组 int next[4][2]={{0,1},{1,0},{0,-1},{-1,0}};//右 下 左 上 int k,sum,tx,ty; sum = getnum(x,y); if(sum>max){ max = sum; mx = x; my = y; } for(k=0;k<=3;k++){ tx = x + next[k][0]; ty = y + next[k][1]; if(tx<0 || tx>n-1 || ty<0 || ty>m-1) continue; if(a[tx][ty]=='.' && book[tx][ty]==0){ book[tx][ty] = 1; dfs(tx,ty); book[tx][ty] = 0; } } return ; }
void move() { finished = NOT; badmove: scratchloc = getnum("Where to"); if (scratchloc < 1 || scratchloc > 20) goto badmove; scratchloc--; for (k = 0; k < 3; k++) { if (cave[loc[YOU]][k] == scratchloc) goto goodmove; } if (scratchloc != loc[YOU]) { (void) puts("Not possible -"); goto badmove; } goodmove: loc[YOU] = scratchloc; if (scratchloc == loc[WUMPUS]) { (void) puts("... OOPS! Bumped a wumpus!"); move_wumpus(); } else if (scratchloc == loc[PIT1] || scratchloc == loc[PIT2]) { (void) puts("YYYYIIIIEEEE . . . Fell in pit"); finished = LOSE; } else if (scratchloc == loc[BATS1] || scratchloc == loc[BATS2]) { (void) puts("ZAP--SUPER BAT SNATCH! Elsewhereville for you!"); scratchloc = loc[YOU] = FNA(); goto goodmove; } }
static void adrs( void ) { int f; char *p = gettoken( &f ); if ( f & TT_NUMBER ) cgout2( getnum(p) ); else RegLabel2( p ); }
static int getalign (const char **fmt) { if (**fmt != '!') return 1; /* no alignment */ else { (*fmt)++; return getnum(fmt, getmaxalign()); } }
int create_num(int num) { int ret; int tmp; while (1) { ret = mylock(); if (ret != 0) { fprintf(stderr, "mylock fail!\n"); exit(1); } tmp = getnum(PRIMER); if (tmp != 0) { ret = myunlock(); if (ret != 0) { fprintf(stderr, "myunlock fail!\n"); exit(1); } continue; } ret = setnum(PRIMER, num); if (ret != 0) { fprintf(stderr, "setnum() error!\n"); exit(1); } ret = myunlock(); if (ret != 0) { fprintf(stderr, "myunlock fail!\n"); exit(1); } } return 0; }
static bool su_expression( su * in_su ) { bool retval = true; char * p = in_su->su_txt; condcode cc; getnum_block value; value.ignore_blanks = false; value.argstart = p; while( *p ) { p++; } value.argstop = p; cc = getnum( &value ); if( cc == notnum ) { retval = false; } else { in_su->su_u = SU_chars_lines; in_su->su_whole = value.result; in_su->su_dec = 0; in_su->su_inch = 0; in_su->su_mm = 0; } return( retval ); }
double Query::getnum(const std::string& x) { int index = m_nmap[x] - 1; if(index < 0) throw std::runtime_error("Column name lookup failure: " + x); return getnum(index); }
void modify_telbook(int no) { int i; char buf[15]; printf("\n\n\t *** 전화번호부 수정부 ***\n\n"); printf("\t번지수정 : [%-5d]\b\b\b\b\b\b", no); i = getnum(); if(i > 100) { printf("번지수를 초과하여 입력하셨습니다.\n"); return; } else if(i != -1) { telbook[i-1] = telbook[no]; telbook[no-1].use = 0; telbook[i-1].use = 1; } else i = no; printf("\t이름수정 : [%-15s]\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b", telbook[i-1].name); gets(buf); if(buf[0] != '\0') strcpy(telbook[i-1].name, buf); printf("\t전화번호 수정 : [%-15s]\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b", telbook[i-1].phone); gets(buf); if(buf[0] != '\0') strcpy(telbook[i-1].phone, buf); printf("번지[%d] 이름[%s] 전화번호[%s]로 수정하였습니다.", i, telbook[i-1].name, telbook[i-1].phone); }
void main() { while(1) { system("cls"); printf("*** MENU ***\n"); printf("1. INPUT\n"); printf("2. PRINT\n"); printf(" 21. SORT PRINT(by name)\n"); printf("3. SEARCH\n"); printf("4. MODIFY\n"); printf("5. DELETE\n"); printf("6. FILE SAVE\n"); printf("7. FILE LOAD\n"); printf("8. EXIT\n"); printf("CHOICE [ ]\b\b\b"); switch(getnum()) { case 1 : input(); break; case 2 : print(); break; case 3 : search(0); break; case 4 : modify_del(1); break; case 5 : modify_del(2); break; case 6 : file_save(); break; case 7 : file_load(); break; case 8 : end(); case 21 : sort_print(); break; default : printf("Please choice again...\n"); getch(); } } }
/* ** options to control endianness and alignment settings */ static void controloptions (lua_State *L, int opt, const gchar **fmt, Header *h) { switch (opt) { case ' ': return; /* ignore white spaces */ case '>': h->endian = BIG; return; case '<': h->endian = LITTLE; return; case '(': h->noassign = TRUE; return; case ')': h->noassign = FALSE; return; case '!': { int a = getnum(fmt, MAXALIGN); if (!isp2(a)) luaL_error(L, "alignment %d is not a power of 2", a); h->align = a; return; } default: { const char *msg = lua_pushfstring(L, "invalid format option '%c'", opt); luaL_argerror(L, 1, msg); } } }
int output_offset(const char *buf, const char *mnemonic, int opcode) { char mn_buf[20]; int mlen = strlen(mnemonic); snprintf(mn_buf, 19, "%s ", mnemonic); mn_buf[19] = '\0'; if(!strncmp(buf, mn_buf, mlen + 1)) { int succ; long int parsed_num = getnum(buf + mlen + 1, &succ); if(!succ) { if(buf[mlen + 1] >= 'a' && buf[mlen + 1] <= 'z') { output_to_label(opcode, buf[mlen + 1] - 'a'); } else { fprintf(stderr, "?\n"); } } else { output_num(opcode, parsed_num); } return 1; } else return 0; }
//位置:接收方 //功能:输入随机数数组,并计算出质询值 //输入: // buff[]——接收到的随机数数组 //输出: // 计算得到的质询值 unsigned int translatenum(InquiryPDU *buff, int Password) { unsigned int recvnum[16]; unsigned int sum = 0; char num = buff->num; char idx = 0; char key; for (char i = 0; i < num; i++) { switch (i % 4) { case 0: key = (buff->each_len[i / 4] & 0xC0) >> 6; break; case 1: key = (buff->each_len[i / 4] & 0x30) >> 4; break; case 2: key = (buff->each_len[i / 4] & 0x0C) >> 2; break; case 3: key = (buff->each_len[i / 4] & 0x03); break; } recvnum[i] = getnum(&key, &idx, buff); sum += recvnum[i]; //printf("得到%d个生成数(16进制):%x\n", i + 1, recvnum[i]); } return sum ^Password; }
void parsearglist(void) { vpush((numvar) arg); // save base of current argblock #if defined(STRING_POOL) vpush((numvar) stringPool); // save stringPool base for later release strpush(idbuf); // save called function's name as arg[-1] #endif numvar *newarg = &vstack[vsptr]; // move global arg pointer to base of new block vpush(0); // initialize new arg(0) (a/k/a argc) to 0 if (sym == s_lparen) { getsym(); // eat arglist '(' while ((sym != s_rparen) && (sym != s_eof)) { #if defined(STRING_POOL) if (sym == s_quote) { vpush((numvar) stringPool); // push the string pointer parsestring(&spush); // parse it into the pool spush(0); // and terminate it getsym(); // eat closing " } else #endif vpush(getnum()); // push the value newarg[0]++; // bump the count if (sym == s_comma) getsym(); // eat arglist ',' and go around else break; } if (sym == s_rparen) getsym(); // eat the ')' else expected(M_rparen); } arg = newarg; // activate new argument frame }
double Query::getnum(const std::string& x) { int index = m_nmap[x] - 1; if (index >= 0) return getnum(index); error("Column name lookup failure: " + x); return 0; }
static long get_cde_slots(IFILE *file, Axq axq) /*;get_cde_slots*/ { long dpos; int n_code, n_data, n_exception; dpos = file->fh_slots; /* position to start of slot info */ ifseek(file, "get-cde-slots-start", dpos, 0); n_code = getnum(file, "n-code"); n_data = getnum(file, "n-data"); n_exception = getnum(file, "n-exception"); get_slot(file, "code"); get_slot(file, "data"); get_slot(file, "exceptions"); return dpos; /* return offset of start of slot info */ }
static const char *getrule(const char *strp, register struct rule *const rulep) { if (*strp == 'J') { /* ** Julian day. */ rulep->r_type = JULIAN_DAY; ++strp; strp = getnum(strp, &rulep->r_day, 1, DAYSPERNYEAR); } else if (*strp == 'M') { /* ** Month, week, day. */ rulep->r_type = MONTH_NTH_DAY_OF_WEEK; ++strp; strp = getnum(strp, &rulep->r_mon, 1, MONSPERYEAR); if (strp == NULL) return NULL; if (*strp++ != '.') return NULL; strp = getnum(strp, &rulep->r_week, 1, 5); if (strp == NULL) return NULL; if (*strp++ != '.') return NULL; strp = getnum(strp, &rulep->r_day, 0, DAYSPERWEEK - 1); } else if (is_digit(*strp)) { /* ** Day of year. */ rulep->r_type = DAY_OF_YEAR; strp = getnum(strp, &rulep->r_day, 0, DAYSPERLYEAR - 1); } else return NULL; /* invalid format */ if (strp == NULL) return NULL; if (*strp == '/') { /* ** Time specified. */ ++strp; strp = getsecs(strp, &rulep->r_time); } else rulep->r_time = 2 * SECSPERHOUR; /* default = 2:00:00 */ return strp; }
/* * Enter visual mode */ void vop(void) { register int c; #if 0 char atube[TUBESIZE + LBSIZE]; #endif ttymode f; /* mjm: was register */ if (!CA && UP == NOSTR) { if (initev) { toopen: merror("[Using open mode]"); putNFL(); oop(); return; } error("Visual needs addressible cursor or upline capability"); } if (OS && !EO) { if (initev) goto toopen; error("Can't use visual on a terminal which overstrikes"); } if (!CL) { if (initev) goto toopen; error("Visual requires clear screen capability"); } if (NS && !SF) { if (initev) goto toopen; error("Visual requires scrolling"); } ovbeg(); bastate = VISUAL; c = 0; if (any(peekchar(), "+-^.")) c = ex_getchar(); pastwh(); vsetsiz(isdigit(peekchar()) ? getnum() : value(WINDOW)); setwind(); ex_newline(); vok(atube); if (!inglobal) savevis(); Outchar = vputchar; vmoving = 0; f = ostart(); if (initev == 0) { vcontext(dot, c); vnline(NOSTR); } vmain(); Command = "visual"; ovend(f); }
/** * Overloaded version of tune that takes the same format string as saved as the "tune" * setting in the listener. It's specified as the frequency, an optional colon and subchannel, a * space, and the band. The decimal in the number is optional. * @param tuneinfo tune info in a form like "88.9:0 FM" * @return true if everything worked out okay */ bool HDCommands::hd_tune(string tuneinfo) {//public // cout << "Tune, 1 arg: " << tuneinfo << endl; bool flag; int i, j; string freq = "", schan = "0", band = "fm"; tuneinfo = removedecimal(tuneinfo); freq = getnum(tuneinfo, 0); i = tuneinfo.find(":"); if (i >= 0) { schan = getnum(tuneinfo, i + 1); } i = tuneinfo.find("AM"); j = tuneinfo.find("am"); if (i >= 0 || j >= 0) band = "am"; flag = hd_tune(freq, schan, band); return flag; }
void check(int num){ /* 0:[black] 1:+ 2:- */ int op[8]={0,0,0,0,0,0,0,0}; int digits[9]={1,2,3,4,5,6,7,8,9}; long i=n-1-1,sum=0; long num1,j; int operation=-1; /* get operations */ while(i>=0){ op[i--]=num%3; num/=3; } i=0; /* calculation */ while(i<=n-1){ /* get the next number */ if(op[i]==0){ j=i; while(op[i]==0 && i<n-1)i++; num1=getnum(j,i); } else{ num1=digits[i]; } /* use the last operation to calculate */ switch(operation){ case -1: sum=num1; break; case 1: sum+=num1; break; case 2: sum-=num1; break; } /* get the next operation */ if(i>=n-1)break; operation=op[i++]; } /* print out */ if(sum==0){ for(i=0;i<n-1;i++){ fprintf(fout,"%d%c",digits[i],op[i]==0?' ':op[i]==1?'+':'-'); } fprintf(fout,"%d\n",digits[i]); } else{ return; } }
void travel(void) { int i; for (i = 0; i < LIST_NR; i++) { printf("%d ", getnum(list[i])); } printf("\n"); }
// // put dot and mark around the region matched by the n th parenthesised // expression from the last search( n=0 = gtr the whole thing) // int region_around_match_command( void ) { int n; n = getnum( u_str(": region-around-match ") ); if( ml_err ) return 0; region_around_match( n ); return 0; }
int getMenu(){ printf(WHITE "1. Jugar Buscaminas\n"); printf(WHITE "2. Sobre el autor\n"); printf(WHITE "3. Salir\n"); printf(YELLOW "Opcion: "); int opt; opt = getnum(); printf(BLUE "%d\n", opt); return opt; }
static int getfamily(const char *f, size_t l, bool local __unused, struct conf *c, const char *p) { if (strncmp(p, "tcp", 3) == 0 || strncmp(p, "udp", 3) == 0) { c->c_family = p[3] == '6' ? AF_INET6 : AF_INET; return 0; } return getnum(f, l, local, &c->c_family, "family", p); }
static ut32 getshift(const char *str) { char type[128]; char arg[128]; char *space; ut32 i=0, shift=0; const char *shifts[] = { "LSL", "LSR", "ASR", "ROR", 0, "RRX" // alias for ROR #0 }; strncpy (type, str, sizeof (type)-1); // handle RRX alias case if (!strcasecmp (type, shifts[5])) { shift = 6; } // all other shift types else { // split the string into type and arg space = strchr (type, ' '); if (!space) return 0; *space = 0; strncpy (arg, ++space, sizeof(arg)-1); for (i=0; shifts[i]; i++) { if (!strcasecmp (type, shifts[i])) { shift = 1; break; } } if (!shift) return 0; shift = (i*2); if ((i = getreg (arg)) != -1) { shift |= 1; i = i<<4; } else { i = getnum (arg); // ensure only the bottom 5 bits are used i &= 0x1f; if (!i) i = 32; i = (i*8); } } i += shift; i = i << 4; r_mem_copyendian ((ut8*)&shift, (const ut8*)&i, sizeof (ut32), 0); return shift; }
void main( ) { char dates[5][12], temp[12] ; long int arr[5], t ; int i, j, valid ; int isvalid( ) ; long int getnum ( char * ) ; clrscr( ) ; printf ( "Enter any five dates (dd\\mm\\yyyy) :-\n" ) ; for ( i = 0 ; i <= 4 ; i++ ) { printf("%d) ",i + 1 ) ; scanf ( "%s", dates[i] ) ; /* Converts date in string to equivalent integer values. */ arr[i] = getnum ( dates[i] ) ; /* Checks for valid date. */ valid = isvalid( ) ; if ( !valid ) { printf ( "This date does not exists. " ) ; printf ( "Enter any other date.\n" ) ; i-- ; } } /* Sorting of dates using Bubble sort method. */ for ( i = 0 ; i <= 3 ; i++ ) { for ( j = 0 ; j <= 3 - i ; j++ ) { if ( arr[j] > arr[j + 1] ) { t = arr[j] ; arr[j] = arr[j + 1] ; arr[j + 1] = t ; strcpy ( temp, dates[j] ) ; strcpy ( dates[j], dates[j + 1]) ; strcpy ( dates[j + 1], temp ) ; } } } printf ( "Dates in sorted order are :- \n" ) ; for ( i = 0 ; i <= 4 ; i++ ) printf ( "%s\n", dates[i] ) ; getch( ) ; }