hdu 1230 哪里错了,WA。。。
各位谢谢拉。#include<stdio.h>#defineM200intprime[40]={1,2,3,5,7,11,13,17,19,23,29,31,37,41,...
各位谢谢拉。
#include<stdio.h>
#define M 200
int prime[40] = {1,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113};
__int64 change(char *str)
{
int temp,count =0;
for(int i=0;str[i]!='\0';i++)
if(str[i]==',')
count++;
__int64 ans =0;
for(i=0;str[i]!='\0';i++)
{
temp =0;
for(;str[i]!=',' && str[i]!='\0';i++)
temp = temp *10 + str[i]-'0';
ans = (ans+temp) * prime[count--] ;
if(str[i]=='\0')
return ans;
}
return ans;
}
void Output(__int64 ans)
{
int stack[M],top =0;
do
{
stack[top++] = ans % prime[top+1];
ans /= prime[top];
}while(ans);
while(top)
{
if(top==1)
printf("%d\n",stack[--top]);
else
printf("%d,",stack[--top]);
}
}
int main()
{
char a[M],b[M];
while(scanf("%s%s",a,b)!=EOF && !(a[0]=='0' && b[0]=='0') )
{
__int64 ans = change(a) + change(b);
Output(ans);
}
return 0;
} 展开
#include<stdio.h>
#define M 200
int prime[40] = {1,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113};
__int64 change(char *str)
{
int temp,count =0;
for(int i=0;str[i]!='\0';i++)
if(str[i]==',')
count++;
__int64 ans =0;
for(i=0;str[i]!='\0';i++)
{
temp =0;
for(;str[i]!=',' && str[i]!='\0';i++)
temp = temp *10 + str[i]-'0';
ans = (ans+temp) * prime[count--] ;
if(str[i]=='\0')
return ans;
}
return ans;
}
void Output(__int64 ans)
{
int stack[M],top =0;
do
{
stack[top++] = ans % prime[top+1];
ans /= prime[top];
}while(ans);
while(top)
{
if(top==1)
printf("%d\n",stack[--top]);
else
printf("%d,",stack[--top]);
}
}
int main()
{
char a[M],b[M];
while(scanf("%s%s",a,b)!=EOF && !(a[0]=='0' && b[0]=='0') )
{
__int64 ans = change(a) + change(b);
Output(ans);
}
return 0;
} 展开
若以下回答无法解决问题,邀请你更新回答
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询