Esempio n. 1
0
void createtable(int level)
{
	int i;
	for(i=1;i<=N;i++)
	{
		if(visit[i]==0)
		{
			visit[i]=1;
			tmp[level]=i;
		}
		else
		{
			continue;
		}
		if(level==N)
		{
			if(value())
			{
				fill();
				total++;
			}
		}
		else
		{
			createtable(level+1);
		}
		visit[i]=0;
	}
	if(level==1)
	{
		total--;
	}
}
Esempio n. 2
0
main(m,n,x,i,r){createtable();scanf("%d",&n);
  for(r=1;n;n--){
    scanf("%d",&x);
    for(i=19999;i;i--)
      if(!table[i]&&!(x%i))break;
    if(m<i)m=i,r=x;
  }
  printf("%d\n",r);
}
Esempio n. 3
0
/* 主程序:散列查找法 */
int main()
{
	int checked[50];   //检查数组
	int i,j,temp;
	long temptime;
	for(i = 0; i < MAX; i++)
	{
		hashtable[i] = BLANK;   //清除散列表
	}

	for(i = 0; i < 50; i++)
	{
		checked[i] = 0;   //清除检查数组
	}

	printf("散列表内容:\n");
	srand(time(&temptime) % 60);    //使用时间初始随机数
	i = 0;
	while(i != NUM)   //生成数组值的循环
	{
		temp = rand() % 50;   //随机数取值0 -49
		if(checked[temp] == 0)   //是否是已有的值
		{
			createtable(temp);    //创建散列表
			printf("%2d = >",temp);
			for(j = 0; j < MAX; j++)  //输出散列表
			{
				printf("[%2d]",hashtable[j]);
			}
			printf("\n");   
			checked[temp] = 1;   //设置此值生成过
			i++;				//下一个数组值
		}
	}

	while(1)  
	{
		printf("\n请输入查找值(0-49) ==>");
		scanf("%d",&temp);   //导入查找值
		if(temp != -1)
		{
			i = linehash(temp);   //调用散列查找
			if(i != -1)
			{
				printf("找到查找值:%d[%d]\n",temp,i);
			}
			else
			{
				printf("没有找到差好值:%d\n",temp);
			}
		}
		else
			exit(1);
	}

}
int main(){
  int a,d,n,c,x;
  createtable();
  for(;;){
    c=0;
    scanf("%d%d%d",&a,&d,&n);
    if(a==0)return 0;
    for(x=a;;x+=d){
      if(!table[x])c++;
      if(c==n){
        printf("%d\n",x);
        break;
      }
    }
  }
}
int main(int argc, char* argv[]){

if(argc!=2){
printf("%s","Usage: <executable name> <password> \n");
exit(1);
}

createtable();

extract(); //extracts secret data (in binary) to secret[]

decrypt(argv[1]); //decompresses and decrypts the received stego object

decompress();

printf("Secret message written to message.txt\n");

return 0;
}
Esempio n. 6
0
int main()
{
	int i;
	FILE *fin  = fopen ("latin.in", "r");
    FILE *fout = fopen ("latin.out", "w");
	fscanf(fin,"%d",&N);
	createtable(1);
	for(i=1;i<=N;i++)
	{
		square[1][i]=i;
		is[i][i]=1;
	}
	if(N<=6)
	{
		judge(2);
		fprintf(fout,"%d\n",cnt*mul(N-1));
	}
	else
	{
		fprintf(fout,"12198297600\n");
	}
	return 0;
} 
Esempio n. 7
0
int main(void)
{
	//#ifdef _DEBUG
	//_CrtSetDbgFlag(_crtDbgFlag|_CRTDBG_LEAK_CHECK_DF);
	//char* pDumMemoryLeak = new char[20];	
	//::mystrcpy(pDumMemoryLeak,"Dum Leak");
	//#endif
	int i=1;
	char buffer[LINE_MAX];
	char* command=buffer;  // check  command
	
	char tableindex[TABLE_MAX][TABLE_NAME_MAX]={0};  //Index of Table		
	Data*** database = (Data***)malloc(sizeof(Data**) * TABLE_MAX);  //Data 
	if(database == NULL) {printf("error in creating Table\n"); exit(1);}
	int j1=0;
	for(j1=0;j1<TABLE_MAX;j1++) database[j1] = NULL;  //Initialize every table to NULL
	Column** columnindex= (Column**) malloc( sizeof(Column*) * TABLE_MAX) ;  //Index of Column 
	if(database == NULL) {printf("error in creating Column\n"); exit(1);}
	int j2=0;
	for(j2=0;j2<TABLE_MAX;j2++) columnindex[j2] = NULL;  //Initialize every column to NULL
	printscreen();   //print screen 
	while(i)
	{
		printf("DB1=>");
		gets(buffer);
		command=buffer;
		while(isspace(*command)){command++;}//ignore ' '
		if(*(command)++!='-')
		{
			printf("command should be started by - \n");
			continue;
		}
		if(*command == 'c')  //create database
		{
			command++;
			while(isspace((*command))){command++;}//ignore ' '
			if(createtable(command,tableindex,columnindex,database) == 0)
				printf("Error in Initializing the table and create it!\n");
			else printf("Succeed in Initializing the table!\n");
			continue;
		}
		if(*command=='i')  // Import DB
		{
			command++;
			while(isspace((*command))){command++;}//ignore ' '
			int i=0;
			char tablename[TABLE_NAME_MAX];
			char filename[20];
			while(*command!=' ')
			{
				tablename[i++]=*(command++);
			}
			tablename[i]='\0';
			while(isspace((*command))){command++;}//ignore ' '
			i=0;
			while(*command!='\0')
			{
				filename[i++]=*(command++);
			}
			filename[i]='\0';
			printf("%d items has been imported\n", ImportTable(tablename,filename,tableindex,columnindex,database));
			continue;
		}
		if(*command=='s')
		{
			command++;
			while(isspace((*command))){command++;}///ignore ' '
			printf("------%d Items has been searched !--------------\n",tablesearch(command,tableindex,columnindex,database) );
			continue;
		}
		if(*command == 'u')  //ignore ' '
		{
			command++;
			while(isspace((*command))){command++;}///ignore ' '
			printf("-------%d Items has been updated!---------------\n",Updatetable(tableindex,columnindex,database,command));
			printf("The result is printed to the File 074090_update.txt \n");
			continue;
		}
		if(*command == 'd')  //delete DB
		{
			command++;
			while(isspace((*command))){command++;}///ignore ' '
			printf("-------%d Items has been Deleted!---------------\n",Deletetable(command,tableindex,columnindex,database) );
			printf("The result is printed to the File 074090_delete \n");
			continue;
		}
		if(*command == 'h')  //help
		{
			help();
			continue;
		}
		if(*command == 'q')  //Quit free Memrory
		{
			quit(database,columnindex,tableindex);
			break;
		}
		else
		{
			puts("Commands can't ben supported!\n");
		}

	}
	printf("\nThank you for using!");
	return 0;
}
Esempio n. 8
0
int main( int argc, char *argv[] )
{

	FILE *dictionary;
	char compmethod;
	char *filename;
	char *test;
	char *nextword;
	int choice;
	int i;
	int line = 0;
	int size = DEFAULT_SIZE; //hash table size
	char buffer[MAX_LINE];
	llist *miswords;
	table *dict;

	if(( choice = getopt( argc, argv, "f:" )) == NONOPT )
	{
		printf("Please pass a command arguments -f <filename>.\n");
		return 0;
	}

	do
	{
		switch ( choice )
		{
		case 'f' :
			filename = (char*)optarg;
			printf ("Reading in file %s\n",filename);
			break;
		case '?' :
			printf("Error! Please use only the -f options (refer to README).\n");
			return 0;
		}
	} while(( choice = getopt( argc, argv, "f:" )) != NONOPT );

	printf("Assignment 3.  074.216, L01.  Trevor Bekolay, 6796723\n\n");
	printf("Which compression algorithm would you like to use? (1 or 2).\n
			\t1. Division\n
			\t2. MAD (Multiply, add, divide)\n");
	printf("How large would you like the hash table?\n
			\t1. 53\n
			\t2. 119\n
			\t3. 1013\n");

	compmethod = getchar();

	if( compmethod != '1' && compmethod != '2' )
	{
		printf("Input not recognized.  Resorting to Division method.\n");
		compmethod = '1';
	}

	i = getchar();

	if( i == '2')
	{
		size = 119;
	}
	else if( i == '3')
	{
		size = 1013;
	}

	printf("Using hash table with size %d!\n",size);

	dict = createtable(size);

	printf("Loading dictionary...\n");
	dictionary = fopen(filename, "r");

	test = fgets(buffer, DICT_MAX - 1, dictionary);

	while( test != NULL )
	{

		for(i = 0; i < strlen(buffer); i++)
			buffer[i] = tolower(buffer[i]);

		printf("%s",buffer);

		addtable( dict, size, buffer, compmethod );

		test = fgets(buffer, DICT_MAX - 1, dictionary);

	}

	printf("Dictionary loaded! Searching for misspelled words...\n");

	miswords = createllist();

	test = fgets(buffer, MAX_LINE -1, stdin);

	while( test != NULL )
	{
		line++;

		nextword = strtok(buffer, " ,.-");

		while( nextword != NULL)
		{
			for(i = 0; i < strlen(nextword) - 1; i++)
				nextword[i] = tolower(nextword[i]);

			if( searchtable(dict, size, nextword, compmethod) )
			{
				addllist( miswords, buffer, line );
			}
			nextword = strtok(NULL, " ,.-");
		}

		test = fgets(buffer, MAX_LINE -1, stdin);

	}


	return 0;

}
Esempio n. 9
0
int main()
{

	table *tbl;
	char *word;
	int size = 53;
	char compmethod = '1';

	printf("Testing all of table (EEE!!)'s methods!!\n\n");
	printf("Creating tbl, adding stuff, searching for stuff.\n");

	tbl = createtable(size);

	word = "hoi";
	printf("Adding word %s\n",word);
	addtable(tbl, size, word, compmethod);

	printtable(tbl, size);

	word = "boi";
	printf("Adding word %s\n",word);
	addtable(tbl, size, word, compmethod);

	printtable(tbl, size);

	word = "owijf";
	printf("Adding word %s\n",word);
	addtable(tbl, size, word, compmethod);

	printtable(tbl, size);

/*

	llist *listt;
	char *word;
	int line;

	printf("Testing all of llist's methods!!\n\n");
	printf("Creating llist listt.  Adding stuff to it.\n");

	listt = createllist();

	word = "hoi";
	line = 11;

	printf("Adding misspelled word %s at line %d\n",word,line);
	addllist(listt, word, line);

	printlist(listt);

	word = "zuh";
	line = 11;

	printf("Adding misspelled word %s at line %d\n",word,line);
	addllist(listt, word, line);

	printlist(listt);


	word = "ajia";
	line = 12;

	printf("Adding misspelled word %s at line %d\n",word,line);
	addllist(listt, word, line);

	printlist(listt);

	word = "hoi";
	line = 15;

	printf("Adding misspelled word %s at line %d\n",word,line);
	addllist(listt, word, line);

	printlist(listt);




	char* buffer = "a wefe";
	int size = 53;
	char compmethod = '2';
	int shash;

	printf("Testing all of hash's methods!!\n\n");
	printf("Using string %s, size %d, compmethod %c\n",buffer,size,compmethod);

	shash = hash( buffer, size, compmethod );

	printf("Result of hashing: %d\n",shash);
*/
	return 0;

}