hdu2024题,为什么我的代码wrong answer?

来源:百度知道 编辑:UC知道 时间:2024/06/05 13:22:05
网址:http://acm.hdu.edu.cn/showproblem.php?pid=2024
#include <iostream>
using namespace std;

int main()
{
int n;
char ch[50];
int index;
int x;

cin>>n;
cin.get();
while(n--)
{
for(index=0; index<50; index++)
ch[index]=0;
cin.getline(ch,sizeof(ch));

if(!(ch[0]=='_'||(ch[0]>='A' && ch[0]<='Z') || (ch[0]>='a' && ch[0]<='z')))
cout<<"no"<<endl;
else
for(index=1; index<50; index++)
{
if(ch[index]=='\0')
{
for(x=index+1; x<50; x++)
{
if(ch[x]!='\0')
break;
}
if(x==50)
cout<<"yes"<<endl;

if(ch[index]=='\0')这里\0表示换行
改成if(ch[index]=='\040')看看
帮你做了一下,改成这样就可以了
#include <iostream>
using namespace std;

int main()
{
int n;
char ch[50];
int index;
int x;

cin>>n;
cin.get();
while(n--)
{
for(index=0; index<50; index++)
ch[index]=0;
cin.getline(ch,sizeof(ch));

if(!(ch[0]=='_'||(ch[0]>='A' && ch[0]<='Z') || (ch[0]>='a' && ch[0]<='z')))
cout<<"no"<<endl;
else
for(index=1; index<50; index++)
{
if(ch[index]=='\040')
{
for(x=index+1; x<50; x++)
{
if(ch[x]!=0)
break;
}
if(x==50)
cout<<"yes"<<endl;
else
cout<<"no"<&l