コード例 #1
0
ファイル: book.c プロジェクト: kou029w/work
// 検索する
void search(){
	char buff[1024];
	char pattern[1024];
	Bookdata *tail;
	Bookdata *matches[1024];
	int count;
	int i;
	
	printf("/");
	input_line(pattern, 1024);
	
	count = 0;
	for(tail = booklist_head; tail != NULL; tail = tail->next){
		if(smatch(pattern, tail->title)
		|smatch(pattern, tail->author)
		|smatch(pattern, tail->publisher)
		|smatch(pattern, tail->note)){
			puts("---");
			matches[count++] = tail;
			show_data(tail);
		}
	}
	
	if(count <= 0) return; // 見つからないので、戻る
	puts("---");
	printf("削除[d] 戻る[x] ");
	input_line(buff, 1024);
	strtolower(buff);
	
	if(strcmp(buff, "d") == 0){
		printf("削除します。よろしいですか? [y/N] ");
		if(select_y('N')){
			for(i=0; i<count; i++){
				delete_data(matches[i]);
			}
		}
		return;
	}else if(strcmp(buff, "x") == 0){
		return;
	}
}
コード例 #2
0
ファイル: ClosestPairs_ILP.c プロジェクト: amosr/papers
float closestpoints(Points ps)
{
    if (ps.size < 100) {
        return naive(ps);
    }

    float y = select_y(ps);

    // aboves = filter (above y) pts
    // belows = filter (below y) pts
    Points aboves = alloc_points(ps.size);
    int aboves_size = 0;
    Points belows = alloc_points(ps.size);
    int belows_size = 0;
    for (int i = 0; i != ps.size; ++i) {
        if (ps.ys[i] < y) {
            aboves.xs[aboves_size] = ps.xs[i];
            aboves.ys[aboves_size] = ps.ys[i];
            aboves_size++;
        }
        if (ps.ys[i] >= y) {
            belows.xs[belows_size] = ps.xs[i];
            belows.ys[belows_size] = ps.ys[i];
            belows_size++;
        }
    }
    aboves.size = aboves_size;
    belows.size = belows_size;

    float above_ = closestpoints(aboves);
    float below_ = closestpoints(belows);

    free_points(aboves);
    free_points(belows);

    float border = minf(above_, below_);


    // aboveB = filter (above y && below (y-border)) pts
    // belowB = filter (below y && above (y+border)) pts
    Points aboveB = alloc_points(ps.size);
    int aboveB_size = 0;
    Points belowB = alloc_points(ps.size);
    int belowB_size = 0;
    for (int i = 0; i != ps.size; ++i) {
        if (ps.ys[i] < y && ps.ys[i] >= (y-border)) {
            aboveB.xs[aboveB_size] = ps.xs[i];
            aboveB.ys[aboveB_size] = ps.ys[i];
            aboveB_size++;
        }
        if (ps.ys[i] >= y && ps.ys[i] < (y+border)) {
            belowB.xs[belowB_size] = ps.xs[i];
            belowB.ys[belowB_size] = ps.ys[i];
            belowB_size++;
        }
    }
    aboveB.size = aboveB_size;
    belowB.size = belowB_size;

    //  dists   = V.concatMap (\p -> V.map (dist p) belowB) aboveB
    float min = border;
    for (int i = 0; i != aboveB.size; ++i) {
        for (int j = 0; j != belowB.size; ++j) {
            float d
                = dist( aboveB.xs[i], aboveB.ys[i]
                      , belowB.xs[j], belowB.ys[j] );
            min = minf(min, d);
        }
    }

    free_points(aboveB);
    free_points(belowB);

    return min;
}