又是ACM题目 很简单的解决方案
又是ACM题目 很简单的
今天做了做了几道ACM题(南京航空航天的),感觉做对了,就是提交不上,哎超感郁闷:
感谢各位高手给指点一下,谢啦!!!!!!!!
http://acm.nuaa.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=1011
[code=C/C++][/code]#include<iostream>
using namespace std;
char c[10][1000];char ch[1000];
bool pipei(char *p,int n1,char c[],int n2)
{
int i=0,j=0;
while(i<n1&&j<n2)
{
if(p[i]==c[j])
{
i++;
j++;
}
else
{
j=j-i+1;
i=0;
}
}
if(i==n1)return true;
else return false;
}
int main()
{
int i,j,n;cin>>n;
scanf("%s",ch);
for(i=0;i<n;++i)
scanf("%s",c[i]);
for(j=0;j<n;++j)
{
if(pipei(c[j],strlen(c[j]),ch,strlen(ch)))cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
return 0;
}
------解决方案--------------------
#include<iostream>
using namespace std;
char c[10][1000];char ch[1000];
bool pipei(char *p,int n1,char c[],int n2)
{
int i=0,j=0;
while(i<n1&&j<n2)
{
if(p[i]==c[j])
{
i++;
j++;
}
else
{
j=j-i+1;
i=0;
}
}
if(i==n1)return true;
else return false;
}
int main()
{
int i,j,n;cin>>n;
scanf("%s",ch);
for(i=0;i<n;++i)
scanf("%s",c[i]);
for(j=0;j<n;++j)
{
if(pipei(c[j],strlen(c[j]),ch,strlen(ch)))cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
return 0;
}
今天做了做了几道ACM题(南京航空航天的),感觉做对了,就是提交不上,哎超感郁闷:
感谢各位高手给指点一下,谢啦!!!!!!!!
http://acm.nuaa.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=1011
[code=C/C++][/code]#include<iostream>
using namespace std;
char c[10][1000];char ch[1000];
bool pipei(char *p,int n1,char c[],int n2)
{
int i=0,j=0;
while(i<n1&&j<n2)
{
if(p[i]==c[j])
{
i++;
j++;
}
else
{
j=j-i+1;
i=0;
}
}
if(i==n1)return true;
else return false;
}
int main()
{
int i,j,n;cin>>n;
scanf("%s",ch);
for(i=0;i<n;++i)
scanf("%s",c[i]);
for(j=0;j<n;++j)
{
if(pipei(c[j],strlen(c[j]),ch,strlen(ch)))cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
return 0;
}
------解决方案--------------------
#include<iostream>
using namespace std;
char c[10][1000];char ch[1000];
bool pipei(char *p,int n1,char c[],int n2)
{
int i=0,j=0;
while(i<n1&&j<n2)
{
if(p[i]==c[j])
{
i++;
j++;
}
else
{
j=j-i+1;
i=0;
}
}
if(i==n1)return true;
else return false;
}
int main()
{
int i,j,n;cin>>n;
scanf("%s",ch);
for(i=0;i<n;++i)
scanf("%s",c[i]);
for(j=0;j<n;++j)
{
if(pipei(c[j],strlen(c[j]),ch,strlen(ch)))cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
return 0;
}