荔园在线
荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀
[回到开始]
[上一篇][下一篇]
发信人: huhaiming (一生只爱她), 信区: Program
标 题: Re: zju的1073题,有个问题解决不了
发信站: 荔园晨风BBS站 (Sat Oct 11 14:21:05 2003), 站内信件
要复习高程,现在没空帮你调试了,我直接贴我ac的程序给你吧
先自己对着看一下,有问题过了明天咱们再讨论^_^
//zju 1073
//by jhun
//April 28th 2003
#include <stdio.h>
#include <string.h>
const int L=65;
char instr[L],outstr[L];
int in[L],out[L];
char str[2*L],result[L];
int len;
int main()
{
int i,j,k,flag,temp,carry;
freopen("1073.in","r",stdin);
while(scanf("%s",instr)!=EOF)
{
memset(out,0,sizeof(out));
strcpy(str,instr);
strcat(str,instr);
len=strlen(instr);
for(j=len-1,i=0;i<j;i++,j--)
instr[i]=instr[i]+instr[j]-(instr[j]=instr[i]);
for(i=0;i<len;i++)
in[i]=instr[i]-48;
flag=1;
for(k=0;k<len;k++)
{
for(i=0;i<len;i++)
{
temp=out[i]+in[i];
if(temp<10)
out[i]+=in[i];
else
{
out[i]=temp%10;
carry=1;
for(j=i+1;j<L;j++)
{
out[j]<9?out[j]++,carry=0:out[j]=0;
if(!carry) break;
}
}
}
if(out[len])
{
flag=0;
break;
}
}
for(i=0;i<len;i++)
result[i]=out[i]+48;
result[len]='\0';
for(j=len-1,i=0;i<j;i++,j--)
{
result[i]=result[i]+result[j]-(result[j]=result[i]);
instr[i]=instr[i]+instr[j]-(instr[j]=instr[i]);
}
if(flag)
{
if(strstr(str,result)==NULL)
printf("%s is not cyclic\n",instr);
else
printf("%s is cyclic\n",instr);
}
else
printf("%s is not cyclic\n",instr);
}
return 0;
}
【 在 jango (姜戈,理想高于一切) 的大作中提到: 】
: 能过SAMPLE,可是交了是WA,不知问题在那里,请指教~,THX
: #include<string.h>
: #include<stdlib.h>
: #include<stdio.h>
: int main()
: {
: char str1[80],str2[80],str[80];
: int intstr[80],intres[80];
: int j,a;
: int i,l;
: char res[80];
: int t[80];
: int mul,b;
: /* if ( freopen("d:\\input.txt","r",stdin) == NULL )
: printf("freopen input error");
: if ( freopen("d:\\output.txt","w",stdout) == NULL )
: printf("freopen output error");*/
: do
: {
: if( scanf("%s",str)==EOF )
: return 0;
: memset(res,0,sizeof(res));
: memset(t,0,sizeof(t));
: memset(intstr,0,sizeof(intstr));
: memset(intres,0,sizeof(intres));
: j=strlen(str);
: strcpy(str1,str);
: strcpy(str2,str);
: strcat(str2,str);
: for(i=0,l=j-1;i<l;i++,l--)
: {
: a=str[i];
: str[i]=str[l];
: str[l]=a;
: }
: for(i=0;i<j;i++)
: intstr[i]=str[i]-48;
: a=j/10;
: b=j-a*10;
: for(l=0;l<j;l++)
: {
: mul=b*intstr[l]+t[l];
: t[l+1]=mul/10;
: intres[l]=mul-t[l+1]*10;
: }
: memset(t,0,sizeof(t));
: if(a!=0)
: {
: for(l=0;l<j;l++)
: {
: mul=a*intstr[l]+t[l+1]+intres[l+1];
: t[l+2]=mul/10;
: intres[l+1]=mul-t[l+2]*10;
: }
: }
: for(i=0,l=j-1;i<j;i++,l--)
: res[l]=intres[i]+48;
: res[j]='\0';
: if(strstr(str2,res)==NULL)
: printf("%s is not cyclic\n",str1);
: else
: printf("%s is cyclic\n",str1);
: }while(1);
: }
--
菩提本无树,明镜亦非台
本来无一物,何处惹尘埃
※ 来源:·荔园晨风BBS站 bbs.szu.edu.cn·[FROM: 192.168.0.200]
[回到开始]
[上一篇][下一篇]
荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店