int main()
{
	char ch='y';
	int choice;
	while(ch=='y' || ch=='Y')
	{
	get_problem(&choice);
	switch(choice)
	{
		case 1:
			{
				double x1,y1,x2,y2,m,b;
				get2_pt(&x1,&y1,&x2,&y2);
				display2_pt(x1,y1,x2,y2);
				slope_intcpt_from2_pt(x1,y1,x2,y2,&m,&b);
				display_slope_intcpt(m,b);
				break;
			}
		case 2:
			{
				double x,y,m,b;
				get_pt_slope(&m,&x,&y);
				display_pt_slope(m,x,y);
				intcpt_from_pt_slope(x,y,m,&b);
				display_slope_intcpt(m,b);
				break;
			}
		default:
		printf("wrong choice\n");		
	}
	printf("Do another conversion (Y or N)=>");
	scanf("\n%c",&ch);	
	}	
	return 0;
}
Beispiel #2
0
/* cs_di_demo2: read a matrix and solve a linear system */
int main (void)
{
    problem *Prob = get_problem (stdin, 1e-14) ;
    demo2 (Prob) ;
    free_problem (Prob) ;
    return (0) ;
}
Beispiel #3
0
int main (int argc, char **argv)
{
    FILE *f ;
    problem *Prob ;
    int trials, ok, demo ;
    if (argc < 2) return (-1) ;
    printf ("cs_test, file: %s\n", argv [1]) ;
    for (demo = 2 ; demo <= 3 ; demo++)
    {
	printf ("demo: %d\n", demo) ;
	for (trials = 0 ; trials < 4000 ; trials++)
	{
	    malloc_count = trials ;
	    f = fopen (argv [1], "r") ;
	    if (!f) return (-1) ;
	    Prob = get_problem (f, (demo == 2) ? 1e-14 : 0) ;
	    fclose (f) ;
	    if (Prob) ok = (demo == 2) ? demo2 (Prob) : demo3 (Prob) ;
	    free_problem (Prob) ;
	    if (malloc_count > 0) break ;
	}
	printf ("demo %d # trials: %d\n", demo, trials) ;
    }
    return (0) ;
}
Beispiel #4
0
/*
 * Usage: ./get_problem oj_name from_problem_id(or index) to_problem_id(or index) [debug]
 */
int main(int argc, char *argv[])
{
	// read config file
	init_conf();

	if (argc < 4 || argc > 5) {
		fprintf(stderr, "Usage: %s oj_name from_problem_id(or index) "
				"to_problem_id(or indx) [debug]\n", argv[0]);
		fprintf(stderr, "Support oj is: ");
		int i = 0;
		for (i = 0; i < oj_cnt; ++i) {
			fprintf(stderr, "%s%c", oj_str[i],
					(i == oj_cnt - 1) ? '\n' : ' ');
		}
		exit(EXIT_SUCCESS);
	}

	DEBUG = (argc == 5);

	int i = 0;
	int from = atoi(argv[2]);
	int to = atoi(argv[3]);
	strcpy(oj_name, argv[1]);
	oj_type = -1;
	for (i = 0; i < oj_cnt; ++i) {
		if (strcmp(oj_name, oj_str[i]) == 0) {
			oj_type = i;
			break;
		}
	}

	if (oj_type < 0) {
		write_log("%s: unsupported oj\n", oj_name);
		exit(EXIT_FAILURE);
	}

	write_log("ojname = %s\n", oj_name);
	write_log("ojurl = %s\n", oj_url[oj_type]);
	write_log("type = %d\n", oj_type);
	write_log("from = %d\n", from);
	write_log("to = %d\n", to);

	curl = prepare_curl();
	if (curl == NULL) {
		write_log("prepare curl handle error.\n");
		exit(EXIT_FAILURE);
	}
	conn = prepare_mysql();
	if (conn == NULL) {
		write_log("prepare mysql handle error.\n");
		cleanup_curl();
		exit(EXIT_FAILURE);
	}
	problem_info = (struct problem_info_t *)malloc(sizeof(struct problem_info_t));
	if (problem_info == NULL) {
		write_log("alloc problem_info memory error.\n");
		cleanup_mysql();
		cleanup_curl();
		exit(EXIT_FAILURE);
	}

	if (oj_type == 2) {		// codeforces
		if (get_cf_problem_id() < 0) {
			write_log("get codeforces problem id error.\n");
			exit(EXIT_FAILURE);
		}
		if (to > cf_pid_len - 1) {
			to = cf_pid_len - 1;
			write_log("index is so large. set it to max index %d.\n", cf_pid_len - 1);
		}
	}

	for (pid = from; pid <= to; ++pid) {
		memset(problem_info, 0, sizeof(struct problem_info_t));
		int ret = get_problem();
		if (ret < 0) {
			write_log("get %s problem %d error.\n", oj_name, pid);
		} else if (ret == 0) {
			write_log("get %s problem %d success.\n", oj_name, pid);

			ret = add_problem();
			if (ret < 0) {
				write_log("add %s problem %d to mysql database error.\n", oj_name, pid);
			} else {
				if (!ret) {
					write_log("add %s problem %d to mysql database success.\n", oj_name, pid);
				} else {
					write_log("%s problem %d already exists, update local problem %d.\n", oj_name, pid, ret);
				}
			}
		} else {
			write_log("%s no problem %d.\n", oj_name, pid);
		}
		if (!DEBUG) {
			execute_cmd("rm -f %d", pid);
		}
		if (pid != to) {
			write_log("get next problem after %d seconds.\n", sleep_time);
		}
		sleep(sleep_time);
	}

	free(problem_info);
	cleanup_curl();
	cleanup_mysql();

	return 0;
}