| 网站首页 | 业界新闻 | 群组 | 人才 | 下载频道 | 博客 | 代码贴 | 编程论坛

得分:0

得分:0

#include<stdio.h>
float cards[7];
int playcards(float n,int o);
int main(void)
{
int i;
for(i=0;i<7;++i)
scanf("%f",&cards[i]);
playcards(13,7);
return 0;
}
int playcards(float n,int o)
{
if(o>1)
{
if(playcards(n-cards[o-1],o-1))
{
printf(" + %.f",cards[o-1]);
return 1;
}
if(playcards(n+cards[o-1],o-1))
{
printf(" - %.f",cards[o-1]);
return 1;
}
if(playcards(n*cards[o-1],o-1))
{
printf(" / %.f",cards[o-1]);
return 1;
}
if(playcards(n/cards[o-1],o-1))
{
printf(" * %.f",cards[o-1]);
return 1;
}
else
{
return 0;
playcards(n,--o);
}
}
if(o==1&&n==cards[0])
{
printf("%.f",cards[0]);
return 1;
}
else
return 0;
}

得分:0

得分:0

#include<stdio.h>
float cards[7];
int playcards(float n,int o);
int main(void)
{
int i,n;
for(i=0;i<7;++i)
scanf("%f",&cards[i]);
for(i=7;i>0;)
{
n=playcards(13,i);
if(n)
break;
else
i--;
}
return 0;
}
int playcards(float n,int o)
{
if(o>1)
{
if(playcards(n-cards[o-1],o-1))
{
printf(" + %.f",cards[o-1]);
return 1;
}
if(playcards(n+cards[o-1],o-1))
{
printf(" - %.f",cards[o-1]);
return 1;
}
if(playcards(n*cards[o-1],o-1))
{
printf(" / %.f",cards[o-1]);
return 1;
}
if(playcards(n/cards[o-1],o-1))
{
printf(" * %.f",cards[o-1]);
return 1;
}
else
return 0;
}
if(o==1&&n==cards[0])
{
printf("%.f",cards[0]);
return 1;
}
else
return 0;
}
得分:0

得分:0

#include <stdio.h>

/*float cards[7];
int playcards(float n, int o);

int main()
{
int i, n;
for (int i = 0; i < 7; i++)
{
scanf("%f", &cards[i]);
}

for (i = 7; i > 0; i--)
{
n = playcards(13, i);
if (n == 1)
{
break;
}
}
return 0;
}

int playcars(float n, int o)
{
if (o > 1)
{
if (playcards(n - cards[o-1], o-1))
{
printf(" + %.f", cards[o-1]);
return 1;
}
if (playcards(n + cards[o-1], o - 1))
{
printf(" - %.f", cards[o-1]);
return 1;
}
if (playcards(n * cards[o-1], o - 1))
{
printf(" / %.f", cards[o-1]);
return 1;
}
if (playcards(n / cards[o-1], o - 1))
{
printf(" * %.f", cards[o-1]);
return 1;
}
else
{
return 0;
}
}

if (o == 1 && n == cards[0])
{
printf("%.f", cards[0]);
return 1;
}
else
{
return 0;
}
}

*/

#define NUM 7

float cards[NUM];
bool calculateCardSum(float result, int count);

int main(int argc, char argv[])
{
int i = 0;
for (int i = 0; i < NUM; i++)
{
scanf("%f", &cards[i]);
}

for (int i = 7; i > 0; i--)
{
if (calculateCardSum(13, i))
{
printf("\n");
break;
}
}
return 0;
}

bool calculateCardSum(float result, int count)
{
if (count > 1)
{
if (calculateCardSum(result - cards[count-1], count - 1))
{
printf(" + %.f", cards[count-1]);
return true;
}
if (calculateCardSum(result + cards[count-1], count - 1))
{
printf(" - %.f", cards[count-1]);
return true;
}
if (calculateCardSum(result * cards[count-1], count - 1))
{
printf(" / %.f", cards[count-1]);
return true;
}
if (calculateCardSum(result / cards[count-1], count - 1))
{
printf(" * %.f", cards[count-1]);
return true;
}
}
else
{
if (result == cards[0])
{
printf("%.f", cards[0]);
return true;
}
}

return false;
}

[此贴子已经被作者于2018-3-11 22:47编辑过]

得分:0

得分:0

得分:0

#include<stdio.h>
#include<math.h>
#include<stdlib.h>

void Input( unsigned [],size_t );
void Print( const unsigned [],size_t,size_t );
void Fun(const unsigned [],size_t);

int main ( void )
{
unsigned s[7];
const size_t size=sizeof (s)/sizeof (*s);

Input(s,size);
Fun(s,size);

return 0;
}

void Input( unsigned arr[],size_t size )
{
size_t i;

for (i=0;i!=size;++i)
if (scanf("%u",&arr[i])!=1)
exit(EXIT_FAILURE);

while (getchar()!='\n');
}

void Print( const unsigned arr[],size_t n,size_t size)
{
#define __GET_DATA(s,n)    \
(((s)>>(n))&3)

const char s[]={"+-*/"};
size_t i;
printf("%u",arr[0]);

for (i=0;i!=size;++i)
{
const size_t k=__GET_DATA(n,i);
printf("%c%u",s[k],arr[i+1]);
}
puts("");

#undef __GET_DATA(s,n)
}

void Fun(const unsigned arr[],size_t size)
{
#define N 13.
#define __GET_DATA(s,n)    \
(((s)>>(n))&3)

const _size=size-1;
unsigned save_size=0;
unsigned save_single;

size_t i;

if (size==0)
return ;

for (i=0;i!=1<<(_size*2);++i)
{
double n=arr[0];
size_t j;

for (j=0;j!=_size;++j)
{
const size_t k=__GET_DATA(i,j);
if (k==0)
n+=arr[j+1];
else if (k==1)
n-=arr[j+1];
else if (k==2)
n*=arr[j+1];
else if (fabs(n)>1e-6)
n/=arr[j+1];
else
break;

if (n==N&&(j+1>save_size))
{
save_size=j+1;
save_single=n;
}
}

}

if (save_size)
Print(arr,save_single,save_size);
else
puts("Na");

#undef  N
#undef  __GET_DATA
}

[此贴子已经被作者于2018-3-12 22:01编辑过]

[code]/*~个性签名:不能超过200个字符 文字将出现在您发表的文章的结尾处 2018-02-19更~*/[/code]
得分:0

• 20
• 2/2页
• 1
• 2