Skip to content

Commit d43c149

Browse files
committed
optimize some function and type
1 parent 9e92472 commit d43c149

File tree

5 files changed

+58
-6
lines changed

5 files changed

+58
-6
lines changed

c/koishi/src/main.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#include "../include/koishi.h"
2+
extern LEVEL getlevel();
23
int main(){
3-
char *level[4]={"easy","normal","hard","extreme"};
4+
char *level[4] = {"easy", "normal", "hard", "extreme"};
45
LEVEL l;
5-
l=getlevel();
6-
while (l<1||l>4){
7-
printf("the number you input(%d) is not listed\nplease input again:\n",l);
8-
l=getlevel();
6+
l = getlevel();
7+
while ( l < 1 || l > 4 ){
8+
printf("the number you input(%d) is not listed\nplease input again:\n", l);
9+
l = getlevel();
910
}
10-
printf("you choose %d %s\n",l,level[l-1]);
11+
printf("you choose %d %s\n", l, level[l-1]);
1112
return 0;
1213
}

cpp/koishi/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
PROJECT(KOISHI)
2+
CMAKE_MINIMUM_REQUIRED(VERSION 2.9)
3+
INCLUDE_DIRECTORIES(
4+
${CMAKE_BINARY_DIR}/../include
5+
)
6+
AUX_SOURCE_DIRECTORY(
7+
${CMAKE_BINARY_DIR}/../src
8+
DIR_SRC
9+
)
10+
ADD_EXECUTABLE(
11+
koishi
12+
${DIR_SRC}
13+
)

cpp/koishi/include/koishi.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef _KOISHI_HPP_
2+
#define _KOISHI_HPP_
3+
#include <cstdio>
4+
#include <cstdlib>
5+
#include <cstring>
6+
#include <iostream>
7+
typedef enum level {
8+
easy=1,
9+
normal,
10+
hard,
11+
extreme
12+
}LEVEL;
13+
#endif

cpp/koishi/src/koishi.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "../include/koishi.hpp"
2+
LEVEL getlevel(){
3+
short int l;
4+
std::cout << "please input the level number:" << std::endl <<
5+
"1.easy" << std::endl <<
6+
"2.normal" << std::endl <<
7+
"3.hard" << std::endl <<
8+
"4.extreme" << std::endl;
9+
std::cin >> l;
10+
return (LEVEL)l;
11+
}

cpp/koishi/src/main.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "../include/koishi.hpp"
2+
extern LEVEL getlevel();
3+
int main(){
4+
std::string level[4] = {"easy", "normal", "hard", "extreme"};
5+
LEVEL l;
6+
l = getlevel();
7+
while ( l < 1 || l > 4 ){
8+
std::cout << "the number you input(" << l << ") is not listed" << std::endl <<
9+
"please input again:" << std::ends << std::endl;
10+
l = getlevel();
11+
}
12+
std::cout << "you choose " << l << " " << level[l-1] << std::endl;
13+
return 0;
14+
}

0 commit comments

Comments
 (0)