Created
June 1, 2016 12:58
-
-
Save lv7777/059613d8c60d5b9f2745f8e485c294fb to your computer and use it in GitHub Desktop.
一日かけてゴミを作るとか最高にゴミだし死にたい。はあ・・・
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define DEBUG | |
#include<stdio.h> | |
#include<stdlib.h> | |
#include<time.h> | |
#include<stdbool.h> | |
#include "lib/MT.h" | |
#ifdef _WINDOWS | |
#pragma comment(lib, "winmm.lib") | |
#include<windows.h> | |
#else | |
#include<time.h> | |
#endif | |
struct Sort{ | |
int no; | |
char *name; | |
char *avg; | |
char *saiaku_saidai; | |
char *alias; | |
}; | |
void missing(struct Sort *); | |
void practiceMode(struct Sort *); | |
struct Sort * sortinit(){ | |
static struct Sort sortArr[]={ | |
{ | |
1,"バブルソート","nasi","n^2","基本交換法" | |
},{ | |
2,"選択ソート","n^2","n^2","基本三法" | |
},{ | |
3,"挿入ソート","n+d","n^2","基本三法" | |
},{ | |
4,"シェルソート","nasi","nlog^2n","" | |
},{ | |
5,"マージソート","nlogn","nlogn","" | |
},{ | |
6,"ヒープソート","nlogn","nlogn","" | |
},{ | |
7,"クイックソート","nlogn","n^2","" | |
},{ | |
8,"ただの(偏った)二分木","n+1/2","n","線形探索法" | |
},{ | |
9,"完全二分木","","","" | |
},{ | |
10,"2分探索法","","","" | |
} | |
}; | |
struct Sort *a=sortArr; | |
return a; | |
//struct Sort *in2=(struct Sort *)in; | |
} | |
int main(void){ | |
struct Sort *arr=sortinit(); | |
char input[2]; | |
char *string="モードを選択してください。1:練習モード,2:フリーモード\n"; | |
write(fileno(stdout),string,strlen(string)); | |
read(fileno(stdin),input,2); | |
switch(atoi(input)){ | |
//練習モード | |
case 1: | |
practiceMode(arr); | |
break; | |
//フリーモード | |
case 2: | |
printf("hello"); | |
break; | |
//extraモード | |
default: | |
printf("hedddllo"); | |
} | |
return 0; | |
} | |
void practiceMode(struct Sort *so){ | |
# ifdef _WINDOWS | |
system("cls"); | |
init_genrand((unsigned long)timeGetTime()); | |
# else | |
system("clear"); | |
init_genrand((unsigned long)time(NULL)); | |
# endif | |
//math_name is array of pointer of char | |
char *math_name[]={"平均比較回数","最悪比較回数"}; | |
bool flag=1; | |
//main | |
while(flag){ | |
//0‾9までの乱数 | |
int algorand=genrand_int31(); | |
algorand=algorand%9+1; | |
double rand=genrand_real1(); | |
int boolrand=(int)(rand+0.5);//キャストを使ったエレガントな4捨5入のhack | |
#ifdef DEBUG | |
printf("%5.5f\n",rand); | |
printf("%d\n",boolrand); | |
printf("%d\n",algorand); | |
#endif | |
//最悪計算量とかオーダーとかの | |
printf("%s の %s は?\n",(so+algorand)->name,math_name[boolrand]); | |
char inputOrder[100]; | |
gets(inputOrder); | |
#ifdef DEBUG | |
printf("入力された値:%s\n",inputOrder); | |
printf("平均:%s\n",(so+algorand)->avg); | |
printf("最悪最大:%s\n",(so+algorand)->saiaku_saidai); | |
#endif | |
//:TODO | |
char *ans=boolrand?(so+algorand)->avg:(so+algorand)->saiaku_saidai; | |
/* | |
//一文字ごとにforを回して\nまで回す | |
for(int i=0;inputOrder=='\0';i++){ | |
inputOrder[i]; | |
} | |
} | |
*/ | |
#ifdef DEBUG | |
printf("strcmp:%d\n",strcmp(inputOrder,ans)); | |
#endif | |
if(!strcmp(inputOrder,ans)){ | |
system("echo 正解です!!!次へ進む?"); | |
char temp[2]; | |
if('n'==read(stdin,temp,2)){ | |
flag=0; | |
} | |
}else{ | |
missing(so+algorand); | |
} | |
} | |
} | |
void missing(struct Sort *algpt){ | |
system("echo ??????"); | |
printf("strcmp:%s\n",algpt->name); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment