CDOJ--1005

本文介绍了一个简单的ACM题目“点球大战”的解题思路及C++代码实现。该题通过判断字符串中是否存在特定字符来计算得分,适用于ACM入门练习。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原题链接:http://www.acm.uestc.edu.cn/problem.php?pid=1005

分析:判断有无"no"即可。

点球大战(penalty) 

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 using namespace std;
 5 char str[105];
 6 int isOK(char *str)
 7 {
 8     int len=strlen(str);
 9     if(str[len-8]==' '&&str[len-7]=='n'&&str[len-6]=='o'&&str[len-5]==' ')
10     return 0;
11     return 1;
12 }
13 int main()
14 {
15     int N,ans1,ans2;
16     char penalty1[10],penalty2[10];
17     while(scanf("%d",&N)==1)
18     {
19         getchar();ans1=0;ans2=0;
20         if(N==0)break;int j=0,k=0;
21         for(int i=0;i<N;i++)
22         {
23             gets(str);
24             if(i%2==0)
25             {
26                 if(isOK(str)){penalty1[j++]='O';ans1++;}
27                 else penalty1[j++]='X';
28             }
29             else
30             {
31                 if(isOK(str)){penalty2[k++]='O';ans2++;}
32                 else penalty2[k++]='X';
33             }
34         }
35         int cnt;
36         if(N%2==0)cnt=N/2;
37         else cnt=(N+1)/2;
38         for(int i=1;i<=cnt;i++)
39         printf("%d ",i);
40         printf("Score\n");
41         for(int i=0;i<j;i++)
42         printf("%c ",penalty1[i]);
43         printf("%d\n",ans1);
44         for(int i=0;i<k;i++)
45         printf("%c ",penalty2[i]);
46         if(k<j)printf("- ");
47         printf("%d\n",ans2);
48     }
49     return 0;
50 }

 

转载于:https://www.cnblogs.com/i-love-acm/archive/2013/06/11/3131462.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值