杭电oj2024题,无法ac,我的代码那里不对?求大神指点
#include<iostream>#include<ctype.h>#include<cstdio>#include<string.h>usingnamespacest...
#include <iostream>
#include <ctype.h>
#include <cstdio>
#include <string.h>
using namespace std;
char a [10003];
int main()
{
int n,j;
while(cin>>n)
{
getchar();
for (int i=0;i<n;i++)
{
gets(a);
int len=strlen(a);
if (a[0]!='_' && isalpha(a[0])==0)
{
cout<<"no"<<endl;
continue;
}
for (int t=1;t<len;t++)
{
if (a[t]!='_' && isalpha(a[t])==0 && isdigit(a[t])==0)
{
cout<<"no"<<endl;
j=1;
break;
}
}
if (j==1) continue;
cout<<"yes"<<endl;
}
}
return 0;
}
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=2024 展开
#include <ctype.h>
#include <cstdio>
#include <string.h>
using namespace std;
char a [10003];
int main()
{
int n,j;
while(cin>>n)
{
getchar();
for (int i=0;i<n;i++)
{
gets(a);
int len=strlen(a);
if (a[0]!='_' && isalpha(a[0])==0)
{
cout<<"no"<<endl;
continue;
}
for (int t=1;t<len;t++)
{
if (a[t]!='_' && isalpha(a[t])==0 && isdigit(a[t])==0)
{
cout<<"no"<<endl;
j=1;
break;
}
}
if (j==1) continue;
cout<<"yes"<<endl;
}
}
return 0;
}
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=2024 展开
2个回答
展开全部
你的j初始化一下就好了,j = -1;
#include <iostream>
#include <ctype.h>
#include <cstdio>
#include <string.h>
using namespace std;
char a [10003];
int main()
{
int n,j = -1;
cin>>n;
getchar();
for (int i=0;i<n;i++)
{
gets(a);
int len=strlen(a);
if (a[0]!='_' && isalpha(a[0])==0)
{
cout<<"no"<<endl;
continue;
}
for (int t=1;t<len;t++)
{
if (a[t]!='_' && isalpha(a[t])==0 && isdigit(a[t])==0)
{
cout<<"no"<<endl;
j=1;
break;
}
}
if (j==1) continue;
cout<<"yes"<<endl;
}
return 0;
}
#include <iostream>
#include <ctype.h>
#include <cstdio>
#include <string.h>
using namespace std;
char a [10003];
int main()
{
int n,j = -1;
cin>>n;
getchar();
for (int i=0;i<n;i++)
{
gets(a);
int len=strlen(a);
if (a[0]!='_' && isalpha(a[0])==0)
{
cout<<"no"<<endl;
continue;
}
for (int t=1;t<len;t++)
{
if (a[t]!='_' && isalpha(a[t])==0 && isdigit(a[t])==0)
{
cout<<"no"<<endl;
j=1;
break;
}
}
if (j==1) continue;
cout<<"yes"<<endl;
}
return 0;
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询