void launch_easy_calc(int *num, char *op) { int i; int x; i = 0; x = 1; while (op[i] != '\0') { if (op[i] == '+' || op[i] == '-') { while (op[i] == '+' || op[i] == '-') { num[x] = easy_calc(num, op, i, x); i++; } } i++; } print_result(num[1]); }
void write_ndef_to_tag(nfc_error_e error, void *user_data){ nfc_tag_h tag; int ret ; printf("write_ndef_to_tag\n"); ret = nfc_manager_get_connected_tag(&tag); printf("nfc_manager_get_connected_tag ret(0x%08x) !\n",ret); if ( ret == NFC_ERROR_NONE) { printf("tag alread attached !\n"); //write NDEF Message nfc_ndef_record_h record; nfc_ndef_message_h message; nfc_ndef_record_create_uri(&record, "http://samsung.com"); nfc_ndef_message_create(&message); nfc_ndef_message_append_record(message, record); printf("Write request!\n"); timeout_counter = 30; nfc_tag_write_ndef(tag, message , _write_completed_cb , NULL); nfc_ndef_message_destroy(message); } else { int ret; success = 0; timeout_counter = 30; ret = nfc_manager_set_tag_discovered_cb( _tag_discovered_cb , NULL); print_result("nfc_manager_set_tag_discovered_cb", ret); printf("Now, Bring the tag closer. Will be writen a new NDEF Message\n"); ecore_timer_add(1, timeout_handler, NULL); } }
/** * 根据位置查询文件信息 */ int query_file_by_curr_location(char* diskName,char* dirId,char *start_ra, char *end_ra, char *start_dec, char *end_dec){ char sql[MAX_BUF_SIZE]; memset(sql, 0, sizeof(sql)); sprintf(sql, "SELECT * FROM `file_info` Where ra_val >= '%s' AND ra_val <= '%s' AND dec_val >= '%s' AND dec_val <= '%s' AND disk_name = '%s' AND directory_id = '%s'", start_ra, end_ra, start_dec, end_dec,diskName,dirId); if (mysql_query(g_conn, sql)){ print_mysql_error(NULL); } g_res = mysql_store_result(g_conn); // 从服务器传送结果集至本地,mysql_use_result直接使用服务器上的记录集 print_result(); free_result(); memset(sql,0,sizeof(sql)); sprintf(sql,"SELECT directory_id FROM 'directory_info' WHERE disk_name = '%s' AND parent_id = '%s'",diskName,dirId); if(mysql_query(g_conn,sql)){ print_mysql_error(NULL); } g_res = mysql_store_result(g_conn); int i; char* childId = (char*)malloc(MAX_BUF_SIZE); while((g_row = mysql_fetch_row(g_res))) { for(i = 0; i < get_fields(g_res); i++) { memset(childId,0,sizeof(childId)); sprintf(childId,"%s",g_row[i]); query_file_by_curr_location(diskName,childId,start_ra,end_ra,start_dec,end_dec); } } return EXIT_SUCCESS; }
double gbt_print_error(CvGBTrees*gbt, const CvMat*values, const CvMat*response, int response_idx, const CvMat*train_sidx) { int count = 0; float*tmp = new float[values->cols]; int t; int total = 0; int train_total = 0; double error = 0; double train_error = 0; for(t=0;t<values->rows;t++) { int s; int c=0; for(s=0;s<values->cols;s++) { tmp[c++] = CV_MAT_ELEM((*values), float, t, s); } CvMat m = cvMat(1, c, CV_32FC1, tmp); float r1 = gbt->predict(&m, 0); float r2 = CV_MAT_ELEM((*response), float, t, 0); bool train = 0; for(s=0;s<train_sidx->cols;s++) { if(CV_MAT_ELEM((*train_sidx), unsigned, 0, s) == t) { train = 1; break; } } if(train) { train_total++; if(r1!=r2) train_error++; } else { total++; if(r1!=r2) error++; } } print_result(train_error * 100 / train_total, error * 100 / total, 0); }
int test_sort() { int failures = 0; const int test_count = 4; printf("\n*** Testing buildin sort ***\n"); cstring *Vojto = cstr_create_str("abcABCdefDEF"); cstring *Albert = Vojto; sort(&Albert); if (strcmp(Albert->str, "ABCDEFabcdef") != 0) { print_cstr_all(Vojto); failures++; } cstr_clear(Vojto); cstr_append_str(Vojto, "123987"); cstring *Pavel = Vojto; sort(&Pavel); if ((strcmp(Pavel->str, "123789") != 0)) { print_cstr_all(Vojto); failures++; } cstr_clear(Vojto); cstr_append_str(Vojto, "1234abCDefGH"); cstring *Adam = Vojto; sort(&Adam); if ((strcmp(Adam->str, "1234CDGHabef") != 0)) { print_cstr_all(Vojto); failures++; } print_result(test_count, failures); return failures; }
static void test_sha512(void) { size_t i; printf("test SHA512\n"); for (i = 0; i < RTEMS_ARRAY_SIZE(test_vectors); ++i) { SHA512_CTX ctx; unsigned char r[64]; const char *s = test_vectors[i]; SHA512_Init(&ctx); SHA512_Update(&ctx, s, strlen(s)); SHA512_Final(r, &ctx); print_result(&r[0], sizeof(r)); rtems_test_assert( memcmp(&r[0], &test_sha512_results[i][0], sizeof(r)) == 0 ); } }
/* * Main * --------------------------------------------------------------------- * - just a wrapper over the inpotrant functions, as ussual */ int main (int argc, char * argv[]) { struct keep_data data; if (parse_arguments(argc, argv, &data) != EXIT_SUCCESS) return EXIT_FAILURE; int sock; if (establish_connection(&data, &sock) != EXIT_SUCCESS) return EXIT_FAILURE; if (send_data(&data.msg, &sock) != EXIT_SUCCESS) return EXIT_FAILURE; char * buffer = NULL; if (get_respose(&sock, &buffer) != EXIT_SUCCESS) return EXIT_FAILURE; print_result(buffer); close(sock); return EXIT_SUCCESS; }
int main() { short n1_sign, n2_sign, ans_sign; short n1[LEN] = {0}, n2[LEN] = {0}, ans[LEN] = {0}; int n1_length, n2_length; char n1_in[LEN], n2_in[LEN]; while ( ~scanf("%s%s", n1_in, n2_in) ) { n1_length = strlen(n1_in); n2_length = strlen(n2_in); n1_sign = sign(n1_in[0]); n2_sign = sign(n2_in[0]); get_num(n1_in, n1, n1_sign, &n1_length); get_num(n2_in, n2, n2_sign, &n2_length); compare_and_compute(n1, n1_sign, n1_length, n2, n2_sign, n2_length, ans, &ans_sign); print_result(ans, ans_sign); clear(n1,n2,ans); } return 0; }
int main(int argc, char *argv[]) { int fd_in, fd_out; struct timeval t0, t1; setup(&fd_in, &fd_out, NULL); CHECK_ERROR(-1, gettimeofday(&t0, NULL)); for (int i = 0; i < BENCHNUM; i++) { run_sendfile(fd_in, fd_out); } CHECK_ERROR(-1, gettimeofday(&t1, NULL)); int diff = get_diff(&t0, &t1); printf("====== BENCH SENDFILE ======\n"); print_result(diff); return 0; }
int main (int argc, char ** argv) { printf ("FCRYPT TESTS\n"); printf ("==================\n\n"); init (argc, argv); if (!gpg_available (newPluginConfiguration ())) { printf ("The test was disabled because gpg could not be found on the system.\n"); return nbError; } test_gpg (); test_init (); test_file_crypto_operations (); test_file_signature_operations (); test_file_faulty_signature (); print_result (ELEKTRA_PLUGIN_NAME); return nbError; }
int test_length() { int failures = 0; const int test_count = 4; cstring *Vojto = cstr_create_str("Ahoj Karle"); printf("\n*** Testing buildin length ***\n"); if (length(Vojto) != 10) { print_cstr_all(Vojto); failures++; } cstr_append_str(Vojto, "1234"); if (length(Vojto) != 14) { print_cstr_all(Vojto); failures++; } cstr_assign_str(Vojto, "Your penis smells like shit."); if (length(Vojto) != 28) { print_cstr_all(Vojto); failures++; } cstr_assign_str(Vojto, ""); if (length(Vojto) != 0) { print_cstr_all(Vojto); failures++; } print_result(test_count, failures); return failures; }
int com_sub(char* arg) { if (!arg) arg = ""; int operands[2]; char *operand; operand = strtok(arg, " "); if (operand) { operands[0] = atoi(operand); } operand = strtok(NULL, " "); if (operand) { operands[1] = atoi(operand); } print_result('-', itoa(operands[0], operand1, base), itoa(operands[1], operand2, base), itoa((operands[0] - operands[1]), answer, base)); return 1; }
int test_sort_insertion() // 插入排序 { // reference: http://cforbeginners.com/insertionsort.html std::vector<int> vec(array_src.begin(), array_src.end()); int tmp = 0, j = 0; for (int i = 1; i < vec.size(); i++){ j = i; while (j > 0 && vec[j] < vec[j - 1]){ tmp = vec[j]; vec[j] = vec[j - 1]; vec[j - 1] = tmp; j--; } } fprintf(stderr, "insertion sort result: \n"); print_result(vec); return 0; }
int main(int argc, char**argv) { parse_args(argc, argv); if(streaming_mode) { streaming_sort(); return 0; } int *data; int nitems = read_file(infile_name, &data); if(nthreads == -1) baseline_nonthreaded_mergesort(data,nitems); else my_threaded_mergesort(data,nitems); print_result(outfile_name, data, nitems); return 0; }
int main(void) { int i, j, k; scanf("%d %d", &m, &c); for(i=1; i<=m; i++) { scanf("%d", &garb); for(j=1; j<=c; j++) { scanf("%d", &in[i][j]); } } for(i=0; i<=c; i++) dynamic[0][i] = 0; for(i=0; i<=m; i++) dynamic[i][0] = 0; for(i=1; i<=c; i++) //i는 현재 기업 번호 { for(j=1; j<=m; j++) //j는 현재 기업에 투자한 금액 { for(k=0; k<=j; k++) { if(dynamic[j][i] < dynamic[k][i-1] + in[j-k][i]) { dynamic[j][i] = dynamic[k][i-1] + in[j-k][i]; invest[j][i] = j-k; } //if } //for k } //for j } //for i printf("%d\n", dynamic[m][c]); print_result(m, c); return 0; }
/* Common function for cursor positionning */ void new_cursor_position(void) { char temp1[5], temp2[12]; print_board(); if (in_check(LIGHT)) { if (sel) { sprintf(temp2, "Check! %c%c-%c%c",oldx,oldy,xcoord,ycoord); } else { sprintf(temp2, "Check! %c%c-",xcoord,ycoord); } if (!is_mini) { pz_draw_header(temp2); } } else { if(sel) { sprintf(temp1,"%c%c-%c%c",oldx,oldy,xcoord,ycoord); } else { sprintf(temp1,"%c%c-",xcoord,ycoord); } if (is_mini) { draw_message(temp1," "); } else { pz_draw_header(temp1); } } print_result(); printf(temp1); printf("\n"); }
TEST(var1_test, autocorr) { Eigen::VectorXd phi0(2), veps(2); Eigen::MatrixXd phi1(2,2); phi0 << 2, 3; phi1 << .80, 0, 0, .64; veps << 1.0, 0.25; alps::alea::util::var1_model<double> model(phi0, phi1, veps); std::cerr << "EXACT MEAN=" << model.mean().transpose() << "\n"; std::cerr << "EXACT TAU =" << model.ctau().diagonal().transpose() << "\n"; alps::alea::autocorr_acc<double> acc(2); fill(model, acc, 400000); alps::alea::autocorr_result<double> res = acc.finalize(); print_result(std::cerr, res); // perform T2 test alps::alea::t2_result t2 = alps::alea::test_mean(res, model.mean()); print_t2(std::cerr, t2); ASSERT_GE(t2.pvalue(), 0.01); }
int test_sort_selection() // 选择排序 { // reference: http://mathbits.com/MathBits/CompSci/Arrays/Selection.htm std::vector<int> vec(array_src.begin(), array_src.end()); int tmp = 0; for (int i = vec.size() - 1; i > 0; i--) { int first = 0; for (int j = 1; j <= i; j++) { if (vec[j] > vec[first]) first = j; } tmp = vec[first]; vec[first] = vec[i]; vec[i] = tmp; } fprintf(stderr, "selection sort result: \n"); print_result(vec); return 0; }
int try_chess(chess_board * ptr_board, int row, int col) { chess_board temp; for(int i=0; i<BOARD_ROWS; i++) for(int j=0; j<BOARD_COLS; j++) if(ptr_board->board_array[i][j] == 0) //只有等于0的点才能放子 { memcpy(&temp, ptr_board, sizeof(chess_board)); put_chess(ptr_board, i, j); if( 8 == ptr_board->chess_number ) { print_result(ptr_board); count++; return 1; } if(try_chess(ptr_board, i, j)) return 1; memcpy(ptr_board, &temp, sizeof(chess_board)); } return 0; }
static int irecv_isend_wait( int cycles, MPI_Datatype sdt, int scount, void* sbuf, MPI_Datatype rdt, int rcount, void* rbuf ) { int myself, tag = 0, i, slength, rlength; MPI_Request sreq, rreq; MPI_Status status; double tstart, tend; MPI_Type_size( sdt, &slength ); slength *= scount; MPI_Type_size( rdt, &rlength ); rlength *= rcount; MPI_Comm_rank( MPI_COMM_WORLD, &myself ); tstart = MPI_Wtime(); for( i = 0; i < cycles; i++ ) { #ifndef FAST MPI_Irecv( rbuf, rcount, rdt, myself, tag, MPI_COMM_WORLD, &rreq ); MPI_Isend( sbuf, scount, sdt, myself, tag, MPI_COMM_WORLD, &sreq ); MPI_Wait( &sreq, &status ); MPI_Wait( &rreq, &status ); /*MPI_Request_free( &sreq );*/ /*MPI_Request_free( &rreq );*/ #else ftmpi_mpi_irecv( rbuf, rcount, rdt, myself, tag, MPI_COMM_WORLD, &rreq ); ftmpi_mpi_isend( sbuf, scount, sdt, myself, tag, MPI_COMM_WORLD, &sreq ); ftmpi_wait( &sreq, &status ); ftmpi_request_free( &sreq ); ftmpi_request_free( &rreq ); #endif } tend = MPI_Wtime(); print_result( rlength, cycles, tend - tstart ); return 0; }
static int scan_dir(const char *path, const char *filename, struct result_info *info) { DIR *d = opendir(path); struct dirent *ent; int count = 0; if (!d) { fprintf(stderr, "%s: opendir: %s\n", path, strerror(errno)); return -1; } printf("%s:\n", path); while ((ent = readdir(d))) { if (ent->d_name[0] != '.') { char fullpath[1024]; struct result_info sub; snprintf(fullpath, sizeof(fullpath), "%s/%s", path, ent->d_name); if (test_scan(fullpath, &sub) > 0) { add_result(info, &sub); count++; } } } closedir(d); if (count > 1) { print_result(filename, info); puts(""); } return count > 0; }
main() { int arr[]={2,3,4,5,6,7,8,7}; int result[2]; pairsum(arr,8,4,result); print_result(result); pairsum(arr,8,5,result); print_result(result); pairsum(arr,8,10,result); print_result(result); pairsum(arr,8,13,result); print_result(result); pairsum(arr,8,15,result); print_result(result); pairsum(arr,8,17,result); print_result(result); }
////////////////////////////////////////////////////////////////////////////// // GetFileList - Invoke the GetFileList (i.e., "dir") service method ////////////////////////////////////////////////////////////////////////////// HRESULT GetFileList( IFileServiceSecureProxy* pFileServiceSecureProxy) { GET_FILE_LIST_RESPONSE* pResponse = NULL; HRESULT hr = S_OK; if( NULL == pFileServiceSecureProxy ) { return E_INVALIDARG; } // Invoke GetFileList method on service _cwprintf(L"Invoking GetFileList method on service... "); hr = pFileServiceSecureProxy->GetFileList( &pResponse ); print_result( hr ); // Print results if( S_OK == hr && NULL != pResponse ) { PWCHAR_LIST *pList = pResponse->FileList; while( pList ) { _cwprintf(L"%s\r\n", (NULL == pList->Element ? L"(null)" : pList->Element)); pList = pList->Next; } } // cleanup if( NULL != pResponse ) { WSDFreeLinkedMemory( pResponse ); pResponse = NULL; } return hr; }
////////////////////////////////////////////////////////////////////////////// // AsyncOperationComplete - Called when the GetFile operation is complete ////////////////////////////////////////////////////////////////////////////// HRESULT STDMETHODCALLTYPE CGetFileAsyncCallback::AsyncOperationComplete( IWSDAsyncResult* pAsyncResult, IUnknown* pAsyncState) { UNREFERENCED_PARAMETER(pAsyncState); GET_FILE_RESPONSE* pResponse = NULL; HRESULT hr = S_OK; // // When the GetFile operation completes, we enter this callback. It's // then our responsibility to call EndGetFile to actually retrieve // the results. // _cwprintf(L"Asynchronous GetFile operation completed.\r\n"); hr = m_pFileServiceSecureProxy->EndGetFile( pAsyncResult, &pResponse ); // Call into our helper method to save the attachment to disk if( S_OK == hr && NULL != pResponse ) { hr = ReceiveBinary( pResponse->Attachment, m_szFile ); } else { _cwprintf(L" GetFile operation failed or returned NULL response: "); print_result( hr ); } // cleanup if( NULL != pResponse ) { WSDFreeLinkedMemory( pResponse ); pResponse = NULL; } return hr; }
int main(int argc, char const *argv[]) { int n ; printf("enter number of vertices\n"); scanf("%d",&n); int a[n+1][n+1], w[n+1][n+1], d[n+1]; int path[n+1]; int i,j; create_matrix(n, a, w); printf("Adj matrix :\n"); for ( i = 1; i <= n; ++i) { for (j = 1; j <= n; ++j) { printf("%d ", a[i][j]); } printf("\n"); } printf("Weight matrix :\n"); for ( i = 1; i <= n; ++i) { for (j = 1; j <= n; ++j) { printf("%d ", w[i][j]); } printf("\n"); } printf("Enter source\n"); int source; scanf("%d",&source); bellman_ford(n, a, w, d, path, source); printf("Distances :\n"); print_result(n, d, path); return 0; }
int main() { char filepath[256]={'\0'}; char stat_str[1024]={'\0'}; int count=0; struct stat_result result; memset(&result,0,sizeof(struct stat_result)); /*char data[1024]="fsfe fa发给d f"; char buf[1024]="fsfe fa发给d f"; stat_word(&result,data); print_result(&result); PLOG("space_count=%d\n",result.space_count); stat_word(&result,buf); print_result(&result); PLOG("space_count=%d\n",result.space_count);*/ while(1) { memset(&result,0,sizeof(struct stat_result)); memset(filepath,0,256); memset(stat_str,0,1024); PRINT_IO("选择txt文本文档:"); gets(filepath); if( file_open_able(filepath) != 0 ) { PRINT_ERROR("file can't open !\n"); continue; } PRINT_IO("输入您要统计的字符串:"); gets(stat_str); count=stat(&result,filepath,stat_str); print_result(&result); PLOG("space_count=%d\n",result.space_count); } return 0; }
static void draw_and_flip_test(void) { struct draw_data data; enum igt_draw_method method; int i; uint64_t res; for (method = 0; method < IGT_DRAW_METHOD_COUNT; method++) { data.method = method; /* Doing everything consumes too much time! */ if (method != IGT_DRAW_MMAP_CPU && method != IGT_DRAW_BLT) continue; printf("\nDraw and flip %s test:\n", igt_draw_get_method_name(method)); for (i = 16; i >= 1; i /= opts.loop_inc) { data.ops_per_vblank = 1; res = do_measurement(draw_and_flip_cb, &data); print_result(i, 1, res); } } }
/* This method is the Dijsktra's algorithm adapted to be used with a binary heap. */ void Dijkstra::FindPath (const int v0, const int v1) { float max_float = std::numeric_limits<float>::max(); //Fill the heap with all vertices dist "inf" for (int i = 0; i < vertices; i++) { heap.Push(heapElem(i, max_float)); visited[i] = false; dist[i] = max_float; } //Modify v0 to has dist = 0 heap.Modify(heapElem(v0, 0)); while (1) { heapElem v = heap.Top(); heap.Pop(); visited[v.idx] = true; if (v.idx == v1) break; //for all adjancent vertex of v: for (Iterator it = al->beginAt(v.idx); it != al->endAt(v.idx); it++) { heapElem w = it.getValue(); float alt = v.dist + w.dist; /* If is not visited and the way to reach w going throught v is shorter or dist[w] is never been updated, update */ if (visited[w.idx] == false && alt < dist[w.idx]) { heap.Modify(heapElem(w.idx, alt)); previous[w.idx] = v.idx; dist[w.idx] = alt; } } } print_result(v0, v1); }
void do_test (int rep) { int r, i, v; for (r = 0; r<rep; r++) { v = vec[nmat]; for (i = nmat-2; i>=0; i--) { v |= vec[i+1]; if (vec[i] && v && matrows[i]==1 && matcols[nmat-1]==1) { *product[i] = matprod_vec_vec (matrix[i], product[i+1], matcols[i]); } else if (v && matcols[nmat-1]==1) { matprod_mat_vec (matrix[i], product[i+1], product[i], matrows[i], matcols[i]); } else if (vec[i] && matrows[i]==1) { matprod_vec_mat (matrix[i], product[i+1], product[i], matcols[i], matcols[nmat-1]); } else if (i==0 && trans1) { matprod_trans1 (matrix[i], product[i+1], product[i], matrows[i], matcols[i], matcols[nmat-1]); } else if (i==nmat-2 && trans2) { matprod_trans2 (matrix[i], product[i+1], product[i], matrows[i], matcols[i], matcols[nmat-1]); } else { matprod_mat_mat (matrix[i], product[i+1], product[i], matrows[i], matcols[i], matcols[nmat-1]); } } } print_result(); }
void bfs(ALGraph *g, int start, int end){ //bfs algorithm int visited[g->vexnum]; int i ; for (i=0; i<g->vexnum; i++) { visited[i] = -100 ; } Queue *q = malloc(sizeof(Queue)) ; initQueue(q); visited[start] = -1 ; enQueue(q,start) ; while (emptyQueue(q) == 0) { int *i = malloc(sizeof(int)) ; deQueue(q,i) ; if (*i == end) { if(visited[end] == -1){ printf("%d-%d\n",end,end) ; return ; } else { print_result(visited,end,end); printf("\n") ; return ; } } ArcNode *s = g->vertices[*i].firstarc ; while (s != NULL) { int w = s->adjvex ; if (visited[w] == -100) { visited[w] = *i ; enQueue(q,w) ; } s = s->nextarc ; } } printf("%d has no path to %d in this graph .\n", start, end) ; }