//算法:动态规划
//思路:递规遍历求解
#include <stdio.h>
#include <stdlib.h>
//算法:动态规划
//思路:递规遍历求解
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void swap(char* a,char* b)//交换处理
{
char temp;
temp=*a;
*a=*b;
*b=temp;
}
void op(char* s,int first,int last,int* c)//遍历处理
{
if(first==last)
{
int n=(int)atoi(s);
if(!(n%11)&&n>*c)
*c=n;
}
else
{
int i;
for(i=first;i<=last;i++)
{
swap(s+first,s+i);
op(s,first+1,last,c);
swap(s+first,s+i);
}
}
}
void main()
{
int n;
int max=0;
char s[16];
printf("Enter a number:\n");
scanf("%d",&n);
if(!(n%11))
{
printf("%d\n",n);
return;
}
_itoa(n,s,10);
op(s,0,strlen(s)-1,&max);
if(max)
printf("%d\n",max);
else
printf("Not\n");
}
#include <string.h>
void swap(char* a,char* b)//交换处理
{
char temp;
temp=*a;
*a=*b;
*b=temp;
}
void op(char* s,int first,int last,int* c)//遍历处理
{
if(first==last)
{
int n=(int)atoi(s);
if(!(n%11)&&n>*c)
*c=n;
}
else
{
int i;
for(i=first;i<=last;i++)
{
swap(s+first,s+i);
op(s,first+1,last,c);
swap(s+first,s+i);
}
}
}
void main()
{
int n;
int max=0;
char s[16];
printf("Enter a number:\n");
scanf("%d",&n);
if(!(n%11))
{
printf("%d\n",n);
return;
}
_itoa(n,s,10);
op(s,0,strlen(s)-1,&max);
if(max)
printf("%d\n",max);
else
printf("Not\n");
}