int main() { std::list<std::string> lst{"this", "is", "a", "list", "of", "string"}; std::vector<int> vec{1, 2, 3, 4, 5, 6, 7}; auto fl = my_find(lst.begin(), lst.end(), "of"); auto fv = my_find(vec.begin(), vec.end(), 3); if (fl != lst.end()) { std::cout << *fl << std::endl; } if (fv != vec.end()) { std::cout << *fv << std::endl; } return 0; }
int main() { const int N = 4; const char* cities[N] = {"Aarhus", "Brussels", "Cincinnati", "Dublin"}; vector<string> v(cities, cities+N); return my_find(v, "Dublin", 2) == different::my_find(v, "Dublin", 2); }
void DFS(int k, int k_father, int depth) { color[k] = 1; anc[k] = dep[k] = depth; for (edge *p = vert[k]; p; p = p->next) { int i = p->to; if (i != k_father && color[i] == 1) anc[k] = anc[k] > dep[i] ? dep[i] : anc[k]; if (color[i] == 0) { DFS(i, k, depth + 1); anc[k] = anc[k] > anc[i] ? anc[i] : anc[k]; if (anc[i] <= dep[k]) { int ii = my_find(i), kk = my_find(k); par[ii] = kk; } } } color[k] = 2; }
static int find_next_case(t_filler *f, t_grid *g) { int xy[4]; int xymax[2]; xy[0] = (f->way | UP) ? 0 : g->hig - 1; xy[1] = (f->way | LEFT) ? 0 : g->wid - 1; xy[2] = (f->way | UP) ? 1 : -1; xy[3] = (f->way | LEFT) ? 1 : -1; xymax[0] = f->y; xymax[1] = f->x; if (my_find(f, g, xy, xymax)) return (1); if (find_next_case2(f, g, xy, xymax)) return (1); xy[0] = f->y; xy[1] = f->x; xymax[0] = (f->way | UP) ? g->hig : -1; xymax[1] = (f->way | LEFT) ? g->wid : -1; return (my_find(f, g, xy, xymax)); }
int main() { std::string s = "but I have heard it works even if you don't believe in it" ; std::string copy_s = s ; std::cout << "position of even before s.replace(0, 4, \"\" ): " << s.find( "even" ) << std::endl ; std::cout << "position of don't before s.replace(0, 4, \"\" ): " << s.find( " don't" ) << std::endl << std::endl; copy_s.replace(0, 4, "" ) ; std::cout << "position of even after s.replace(0, 4, \"\" ): " << copy_s.find( "even" ) << std::endl ; std::cout << "position of don't after s.replace(0, 4, \"\" ): " << copy_s.find( " don't" ) << std::endl << std::endl; s.replace(0, 4, "" ).replace( my_find( s, "even" ) , 4, "only" ) .replace( my_find( s, " don't" ), 6, "" ); std::cout << "Result: " << s << std::endl ; }
int main() { //freopen("in.txt", "r", stdin); int nca; scanf("%d", &nca); while (nca--) { int top = -1; memset(vert, 0, sizeof (vert)); scanf("%d%d", &n, &m); for (int x, y, i = 0; i < m; i++) { scanf("%d%d", &x, &y); add_edge(x, y, top); add_edge(y, x, top); } memset(dep, 0, sizeof (dep)); memset(anc, 0, sizeof (anc)); memset(par, -1, sizeof (par)); memset(color, 0, sizeof (color)); for (int i = 1; i <= n; i++) { if (!color[i])DFS(i, -1, 1); } memset(anc, 0, sizeof (anc)); for (int ii, i = 1; i <= n; i++) { ii = my_find(i); anc[ii]++; } int ans = 0; for (int ii, i = 1; i <= n; i++) { ii = my_find(i); int tem = anc[ii]; if (ans < tem) { ans = tem; } } if (ans == 1)ans = 0; printf("%d\n", ans); } return 0; }
int main() { int l = 0; int arr[] = { 4, 5, 6, 7, 8, 9, 0, 33, 22, 88, 99, 74742,2,1,77,55,44 }; int k = 5; int count = sizeof(arr) / sizeof(arr[0]); exchange_sort(arr,count ); for (int i = 0; i < count; i++) { printf("%d ", arr[i]); } printf("\n"); printf("%d\n",my_find(arr, count, k,l) ); return 0; }
void my_find(t_loop *loop, t_ray *ray, t_set *set, int rec) { set->dist = 0; set->color = 0; set->type = 0; my_find_sphere(&loop->geom, ray, set); my_find_cylinder(&loop->geom, ray, set); my_find_cone(&loop->geom, ray, set); my_find_plan(&loop->geom, ray, set); set->col = loop->palette[set->color]; if (set->dist > 0 && rec != -1) find_light(loop, ray, set); if (set->type == 1 && rec < REFL_NB && rec != -1) { *ray = my_ray_reflexion(ray, set); my_find(loop, ray, set, rec + 1); } }
/* Fonction: internal_command * Entrees: un entier représentant la position de la commande * a effectuer dans le tableau commande[] * * Sortie: aucune * * Execute une commande externe */ int internal_command(int pos) { if( strcmp(commande[pos], "exit") == 0) {stockCommande(); my_exit(commande); return 1;} else if(strcmp(commande[pos], "cd") == 0) {stockCommande(); chdir(commande[pos+1]); return 1;} else if(strcmp(commande[pos], "cat") == 0) {stockCommande(); my_cat(commande[pos+1], commande[pos+2]); return 1;} else if(strcmp(commande[pos], "history") == 0) {stockCommande(); my_history(); return 1;} else if(strcmp(commande[pos], "cp") == 0) {stockCommande(); my_copy(commande[pos+1], commande[pos+2]); return 1;} else if(strcmp(commande[pos], "find") == 0) {stockCommande(); my_find(0); return 1;} else return 0; }
static void maybe_push_modules(int fd, char **modules) { char **p; int err; for(p=modules; *p; p++){ err = my_find(fd, *p); if(err == 1) break; if(err < 0 && errno != EINVAL) fatalperror(net, "my_find()"); /* module not pushed or does not exist */ } /* p points to null or to an already pushed module, now push all modules before this one */ for(p--; p >= modules; p--){ err = ioctl(fd, I_PUSH, *p); if(err < 0 && errno != EINVAL) fatalperror(net, "I_PUSH"); } }
int my_find(int x) { if (par[x] == -1)return x; return par[x] = my_find(par[x]); }
int main() { char val1[32] = "Roy Bayraktaryan Bahian"; char val2[32] = "Hello"; char val3[32] = "_World_!!!"; char val4[32] = ""; char *p; int i; char str[128] = "life is great!"; my_str("\nmy_find()\n-----------------\n"); my_str("1: my_find('Roy Bayraktaryan Bahian', 'y') = "); p = my_find(val1, 'y'); if(p) my_char(*p); my_char('\n'); my_str("2: my_find('Roy Bayraktaryan Bahian', 'z') = "); p = my_find(val1, 'z'); if(p) my_char(*p); my_char('\n'); my_str("3: my_find('', 'y') = "); p = my_find(val4, 'y'); if(p) my_char(*p); my_char('\n'); my_str("4: my_find(NULL, 'y') = "); p = my_find(NULL, 'y'); if(p) my_char(*p); my_char('\n'); my_str("5: my_find('Roy Bayraktaryan Bahian', space) = "); p = my_find(val1, ' '); if(p) my_char(*p); my_char('\n'); /***********************************************************/ my_str("\nmy_rfind()\n-----------------\n"); my_str("1: my_rfind('Roy Bayraktaryan Bahian', 'y') = "); p = my_rfind(val1, 'y'); my_char(*p); my_char('\t'); my_int(*p); my_char('\n'); my_str("2: my_rfind('Roy Bayraktaryan Bahian', 'z') = "); p = my_rfind(val1, 'z'); my_char(*p); my_char('\t'); my_int(*p); my_char('\n'); my_str("3: my_rfind('', 'y') = "); p = my_rfind(val4, 'y'); my_char(*p); my_char('\t'); my_int(*p); my_char('\n'); my_str("4: my_rfind(NULL, 'y') = "); p = my_rfind(NULL, 'y'); if(p)my_char(*p); my_char('\n'); my_str("5: my_rfind('Roy Bayraktaryan Bahian', '') = "); p = my_rfind(val1, '@');/*it doesn't work NULL char of course*/ my_char(*p); my_char('\t'); my_int(*p); my_char('\n'); /***********************************************************/ my_str("\nmy_strcat()\n-----------------\n"); my_str("1: my_strcat('Hello', 'empty') = "); p = my_strcat(val2, val4); my_char(*p); my_char('\t'); my_int(*p); my_char('\t'); my_str(p); my_char('\n'); my_str("2: my_strcat('Hello', '_World_!!!') = "); p = my_strcat(val2, val3); my_char(*p); my_char('\t'); my_int(*p); my_char('\t'); my_str(p); my_char('\n'); my_str("3: my_strcat('Hello', 'empty') = "); p = my_strcat(val2, val4); my_char(*p); my_char('\t'); my_int(*p); my_char('\t'); my_str(p); my_str("\t val2 changed NO MORE HELLO "); my_char('\n'); my_str("4: my_strcat('Hello_World_!!!', 'NULL') = "); p = my_strcat(val2, NULL); my_char(*p); my_char('\t'); my_int(*p); my_char('\t'); my_str(p); my_char('\n'); my_str("5: my_strcat('EMPTY', 'Hello World!!!') = "); p = my_strcat(val4, val2); my_char(*p); my_char('\t'); my_int(*p); my_char('\t'); my_str(p); my_char('\n'); my_str("6: my_strcat(NULL, 'Hello World!!!') = "); p = my_strcat(NULL, val2); if(p) my_char(*p); my_char('\n'); my_str("7: my_strcat(NULL, NULL) = "); p = my_strcat(NULL, NULL); if(p) my_char(*p); my_char('\n'); /***********************************************************/ my_str("\nmy_strcmp()\n-----------------\n"); my_str("1: my_strcmp('Roy', 'Bahian') = "); my_int(my_strcmp("Roy", "Bahian")); my_char('\n'); my_str("2: my_strcmp('Bahian', 'Roy') = "); my_int(my_strcmp("Bahian", "Roy")); my_char('\n'); my_str("3: my_strcmp('Roy', Empty) = "); my_int(my_strcmp("Roy", "")); my_char('\n'); my_str("4: my_strcmp('Roy', NULL) = "); my_int(my_strcmp("Roy", NULL)); my_char('\n'); my_str("5: my_strcmp('Empty', 'Bahian') = "); my_int(my_strcmp("", "Bahian")); my_char('\n'); /* my_str("6: my_strcmp(NULL, 'Bahian') = "); my_int(my_strcmp(NULL, "Bahian")); my_char('\n'); my_str("7: my_strcmp(NULL, NULL) = "); my_int(my_strcmp(NULL, NULL)); my_char('\n'); */ my_str("8: my_strcmp('Roy', 'Roy') = "); my_int(my_strcmp("Roy","Roy")); my_char('\n'); return 0; }
int main(int argc, char *argv[]) { int ch, num = 10; char* addr = strdup("127.0.0.1:19999"); void (*func)(const char* addr, int num, bool enable_cache) = NULL; bool use_mysql = false, enable_cache = false; while ((ch = getopt(argc, argv, "hs:aqgQuUn:mdc")) > 0) { switch (ch) { case 'h': usage(argv[0]); return (0); case 's': free(addr); addr = strdup(optarg); break; case 'a': func = hs_insert; break; case 'q': func = hs_find; break; case 'g': func = hs_find2; break; case 'Q': func = hspool_find; break; case 'u': func = hs_update; break; case 'U': func = hspool_update; break; case 'n': num = atoi(optarg); break; case 'm': use_mysql = true; break; case 'd': debug_on = true; break; case 'c': enable_cache = true; break; default: break; } } if (use_mysql) { printf("mysql\n"); my_find(addr, num); return (0); } logger_open("test.log", "test", "all:2"); if (func != NULL) func(addr, num, enable_cache); else usage(argv[0]); free(addr); return (0); }