69,373
社区成员
发帖
与我相关
我的任务
分享
#include<stdio.h>
#include<string.h>
#include<math.h>
int yushu(int x,int y);
int shu(char*s,int z);
int main()
{
int la,lb,A,B,r;
char a[1025],b[1025];
while(gets(a))
{
gets(b);
if(a[0]=='\n'||b[0]=='\n')
{
printf("1\n");
continue;
}
else
{
la=strlen(a);
lb=strlen(b);
A=shu(a,la);
B=shu(b,lb);
r=yushu(A,B);
printf("%d\n",r);
}
}
return 0;
}
int shu(char*s,int z)
{
int sum=1,k=1,N,n=0,j,i;;
for(i=z-1;i>=0;i--)
{
if(s[i]==')')
{
N=k;
k=0;
j=0;
sum*=(int)pow(N,n);
continue;
}
if(s[i]=='(')
{
n=k;
k=0;
j=0;
continue;
}
k+=(s[i]-'0')*(int)pow(10,j);
}
N=k;
sum*=(int)pow(N,n);
return sum;
}
int yushu(int x,int y)
{
int k;
if(x<y)
{
k=y;
y=x;
x=k;
}
if(x%y==0)
return y;
else
return yushu(y,x%y);
}
#include<stdio.h>
#include<string.h>
#include<math.h>
typedef struct
{
unsigned value;
unsigned number;
} factor_t;
typedef struct
{
factor_t factor_buffer[128];
unsigned factor_count;
} factor_chain_t;
void shu1(factor_chain_t *p,char*s,int z);
void shu2(factor_chain_t *p,factor_chain_t *q,char*s,int z);
int main()
{
int la,lb;
//static int string1[13000],string2[13000];
static factor_chain_t string1, string2;
unsigned
char a[1025],b[1025]; //char a[50000],b[50000];
while(gets(a))
{
gets(b);
la=strlen(a);
lb=strlen(b);
if(la==0||lb==0)
{
printf("1\n");
continue;
}
memset(&string1, 0, sizeof(string1));
memset(&string2, 0, sizeof(string2));
shu1(&string1,a,la);
shu2(&string1,&string2,b,lb);
}
return 0;
}
void shu1(factor_chain_t *p,char*s,int z)
{
int i;
unsigned k=1,N,n=0,j;
for(i=z-1;i>=0;i--)
{
if(s[i]==')')
{
N=k;
k=0;
j=0;
//p[N]=n;
p->factor_buffer[p->factor_count].number = N;
p->factor_buffer[p->factor_count].value = n;
p->factor_count++;
continue;
}
if(s[i]=='(')
{
n=k;
k=0;
j=0;
continue;
}
k+=(s[i]-'0')*(int)pow(10,j);
j++;
}
N=k;
//p[N]=n;
p->factor_buffer[p->factor_count].number = N;
p->factor_buffer[p->factor_count].value = n;
p->factor_count++;
}
unsigned get_factor_value (factor_chain_t *p, unsigned N)
{
unsigned i;
for (i = 0; i < p->factor_count; i++)
{
if (p->factor_buffer[i].number == N) return p->factor_buffer[i].value;
}
return 0;
}
//void shu2(int*p,int*q,char*s,int z)
void shu2(factor_chain_t *p,factor_chain_t *q,char*s,int z)
{
int i;
unsigned sum=1,k=1,N,n=0,j;
unsigned p_N, q_N;
for(i=z-1;i>=0;i--)
{
if(s[i]==')')
{
N=k;
k=0;
j=0;
/*
q[N]=n;
if(p[N]!=0&&p[N]>q[N])
sum*=(int)pow(N,q[N]);
if(p[N]!=0&&p[N]<=q[N])
sum*=(int)pow(N,p[N]);
*/
q->factor_buffer[q->factor_count].number = N;
q->factor_buffer[q->factor_count].value = n;
q->factor_count++;
p_N = get_factor_value(p, N);
q_N = get_factor_value(q, N);
if(p_N!=0&&p_N>q_N)
sum*=(unsigned)pow(N,q_N);
if(p_N!=0&&p_N<=q_N)
sum*=(unsigned)pow(N,p_N);
continue;
}
if(s[i]=='(')
{
n=k;
k=0;
j=0;
continue;
}
k+=(s[i]-'0')*(unsigned)pow(10,j);
j++;
}
N=k;
/*
q[N]=n;
if(p[N]!=0&&p[N]>q[N])
sum*=(int)pow(N,q[N]);
if(p[N]!=0&&p[N]<=q[N])
sum*=(int)pow(N,p[N]);
*/
q->factor_buffer[q->factor_count].number = N;
q->factor_buffer[q->factor_count].value = n;
q->factor_count++;
p_N = get_factor_value(p, N);
q_N = get_factor_value(q, N);
if(p_N!=0&&p_N>q_N)
sum*=(unsigned)pow(N,q_N);
if(p_N!=0&&p_N<=q_N)
sum*=(unsigned)pow(N,p_N);
printf("%u\n",sum); //printf("%d\n",sum);
}
#include<stdio.h>
#include<string.h>
#include<math.h>
void shu1(int*p,char*s,int z);
void shu2(int*p,int*q,char*s,int z);
int main()
{
int la,lb;
static int string1[13000],string2[13000];
char a[50000],b[50000];
while(gets(a))
{
gets(b);
la=strlen(a);
lb=strlen(b);
if(la==0||lb==0)
{
printf("1\n");
continue;
}
shu1(string1,a,la);
shu2(string1,string2,b,lb);
}
return 0;
}
void shu1(int*p,char*s,int z)
{
int k=1,N,n=0,j,i;
for(i=z-1;i>=0;i--)
{
if(s[i]==')')
{
N=k;
k=0;
j=0;
p[N]=n;
continue;
}
if(s[i]=='(')
{
n=k;
k=0;
j=0;
continue;
}
k+=(s[i]-'0')*(int)pow(10,j);
j++;
}
N=k;
p[N]=n;
}
void shu2(int*p,int*q,char*s,int z)
{
int sum=1,k=1,N,n=0,j,i;
for(i=z-1;i>=0;i--)
{
if(s[i]==')')
{
N=k;
k=0;
j=0;
q[N]=n;
if(p[N]!=0&&p[N]>q[N])
sum*=(int)pow(N,q[N]);
if(p[N]!=0&&p[N]<=q[N])
sum*=(int)pow(N,p[N]);
continue;
}
if(s[i]=='(')
{
n=k;
k=0;
j=0;
continue;
}
k+=(s[i]-'0')*(int)pow(10,j);
j++;
}
N=k;
q[N]=n;
if(p[N]!=0&&p[N]>q[N])
sum*=(int)pow(N,q[N]);
if(p[N]!=0&&p[N]<=q[N])
sum*=(int)pow(N,p[N]);
printf("%d\n",sum);
}
你好,我也觉的我的方法太挫了,按照你的想法我改了程序,而且我把数组的长度也加大了,可是还是runtime erro,怎么会这样啊?该怎么办呢?路过的帮帮忙,谢谢!!