http://acm.hdu.edu.cn/showproblem.php?pid=2539
题意:略:
思路;方法很明确,就是可能在输入时会有点麻烦,这里也有必要说一下!我当初也是在输入时出错,导致一直错;
在输入时用到strstr函数,在输入的一串字符中找到(no good )切记这里必须是(no good )为什么呢??因为:如果你用(good),在no good 字符串中也有,因此就判断不出是(no good 还是good),而且答案会是只有good,因此这里与必要注意下。易犯错。。
具体详情见代码:
#include<iostream>
#include<cstdio>
#include<algorithm >
#include<cstring>
#include<cmath>
#include<cstdlib>
using namespace std;
char str[1005];
int s1,s2;
char a[101];
char b[101];
int main()
{
int n;
while(scanf("%d",&n)!=EOF&&n)
{
getchar();//****注意,,,
s1=0;s2=0;
for(int i=0;i<n;i++)
{
gets(str);//用到这个必须要注意,前面必须加(getchar());
char* p=strstr(str," no good");
if(p&&strlen(p)==8)
{
if(i%2==0)
a[i/2]='X';
else
b[(i-1)/2]='X';
}
else
{
if(i%2==0)
{
a[i/2]='O';
s1++;
}
else
{
b[(i-1)/2]='O';//这里的i要注意,,
s2++;
}
}
}
if(n&1)
b[(n-1)/2]='-';
for(int i=0;i<(n+1)/2;i++)
cout<<i+1<<" ";
cout<<"Score"<<endl;
for(int i=0;i<(n+1)/2;i++)
cout<<a[i]<<" ";
cout<<s1<<endl;
for(int i=0;i<(n+1)/2;i++)
cout<<b[i]<<" ";
cout<<s2<<endl;
}
return 0;
}