8球胜负(eight)

来源:互联网 发布:ppt怎么弄数据展现 编辑:程序博客网 时间:2024/05/04 12:02
8球胜负(eight)

8球胜负(eight)
晚上睡不着,无聊着码了码代码 - -
这个题还比较简单。。。一个多小时完工吧。。。

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    chartemp 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      
51    return 0;
52 }
53 
54 int main(){
55    int ball_num[100];
56    string ball_color[100];
57    int i=0;
58    int n;
59    while(1){
60       cin>>ball_num[i];
61       if (ball_num[i]==0break;
62       cin>>ball_color[i];
63        i++;
64    }
65    n=i;
66    for (i=0;i
67       winner(ball_num[i],ball_color[i]);
68    }
69    return 0;
70 }

其中将字符串转为字符数组的时候百度了一下,本来是想用strncpy函数的,但是提交OJ的时候说‘strncpy’was not declared in this scope,本地编译都通过了,略不解
原创粉丝点击