8球胜负(eight)
来源:互联网 发布:ppt怎么弄数据展现 编辑:程序博客网 时间:2024/05/04 12:02
晚上睡不着,无聊着码了码代码 - -
这个题还比较简单。。。一个多小时完工吧。。。
C++语言: 高亮代码由发芽网提供
01 #include
02 #include
03
04 using namespace std;
05
06 int ball_compare(char color,string ball_color){
07 int jsq=0,i=0;
08 // char temp[15];
09 // strncpy(temp,ball_color.c_str(),ball_color.length());
10 char* temp = new char(ball_color.length()+1);
11 sprintf(temp ,"%s" , ball_color.c_str());
12 if (color=='F'){
13 if (temp[ball_color.size()-1]=='B') return 'B';
14 if (temp[ball_color.size()-1]=='L') return 'L';
15 }
16 else if(color=='Y'){
17 for(i=0;i<(ball_color.size());i++){
18 if (temp[i]=='Y') jsq++;
19 }
20 return jsq;
21 }
22 else if(color=='R'){
23 for(i=0;i<(ball_color.size());i++){
24 if (temp[i]=='R') jsq++;
25 }
26 return jsq;
27 }
28 }
29
30 int winner(int ball_num,string ball_color){
31 if (ball_num<<spanstyle="color: rgb(0, 153, 153);">8){
32 if (ball_compare('F',ball_color)=='B')
33 cout<<"Yellow"<<endl;
34 else
35 cout<<"Red"<<endl;
36 }
37 else{
38 if (ball_compare('F',ball_color)=='B'){
39 if (ball_compare('R',ball_color)==7)
40 cout<<"Red"<<endl;
41 else
42 cout<<"Yellow"<<endl;
43 }
44 if (ball_compare('F',ball_color)=='L'){
45 if (ball_compare('Y',ball_color)==7)
46 cout<<"Yellow"<<endl;
47 else
48 cout<<"Red"<<endl;
49 }
50 }
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50