8球胜负(eight)

8球胜负(eight)

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

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<<span style="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]== 0 break;
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,本地编译都通过了,略不解
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值