1 竖式问题
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <string.h>
#define SWAP(x,y)(x=x+y,y=x-y,x=x-y)
#define INF 100000000
#define MAXN 1000
int a[MAXN];
int main(void)
{
int i,ok,abc,de,x,y,z;
int count=0;
char s[20],buf[99];
scanf("%s",s);
for(abc=111;abc<=999;abc++)
{
for(de=11;de<99;de++)
{
x=abc*(de%10);
y=abc*(de/10);
z=abc*de;
sprintf(buf,"%d%d%d%d%d",abc,de,x,y,z);
ok=1;
for(i=0;i<strlen(buf);i++)
{
if(strchr(s,buf[i])==NULL) ok=0;
}
if(ok)
{
printf("<%d>\n",++count);
printf("%5d\nX%4d\n-----\n%5d\n%4d\n-----\n%5d\n\n",abc,de,x,y,z);
}
}
}
printf("The number of solution = %d",count);
return 0;
}
2. 最长回文字串
/*
============================================================================
Name : ch1_inputandoutput.c
Author : Adam Zam
Version :
Copyright : Your copyright notice
Description : Hello World in C, Ansi-style
============================================================================
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <string.h>
#include <ctype.h>
#define SWAP(x,y)(x=x+y,y=x-y,x=x-y)
#define INF 100000000
#define MAXN 5000+10
//#define LOCAL
char s[MAXN],buf[MAXN];
typedef struct p{
int locate;
char str[MAXN];
}beautiStr;
int Judge(beautiStr t);
/*
int main(void)
{
int len;
int i;
char temp[MAXN];
beautiStr bStr;
//查找最长的回文字
fgets(buf,sizeof(s),stdin);
len=(int)strlen(buf);
#ifdef LOCAL
printf("%c",buf[1]);
printf("%d",(int)strlen(buf));
#endif
//转化为大写字母
for(i=0;i<len;i++)
{
if(isalpha(buf[i]))
{
buf[i]=toupper(buf[i]);//转换为大写字母
}
}
#ifdef LOCAL
printf("%s",buf);
#endif
int j;
int maxLen=2;
//从中间开始查找
for(j=0;j<len;j++)
for(i=maxLen;i<len;i++)
{
//printf("%d",i);
memcpy(bStr.str,buf+j,i);
bStr.str[i]=0;//末尾加一个0,表示一个字符串结束
//printf("%s",temp);
bStr.locate=i;
if(Judge(bStr)==1)
{
maxLen=i;
printf("%s\n",bStr.str);
}
//i++;
}
#ifdef LOCAL
memcpy(bStr.str,"1221",5);
printf("%s\n",bStr.str);
printf("\n#%d\n",Judge(bStr));
#endif
return 0;
}
int Judge(beautiStr t)
{
int len = strlen(t.str);
int i=0;
for(i=0;i<len;i++)
{
if(t.str[i]!=t.str[len-1-i])
{
return 0;
}
}
return 1;
}
*/
char p[MAXN];
int main()
{
int n,m=0,max=0,x,y;
int i,j;
fgets(buf,sizeof(s),stdin);
n=strlen(buf);
for(i=0;i<n;i++)
{
if(isalpha(buf[i]))
{
p[m]=i;
s[m++]=toupper(buf[i]);
}
}
//m为实际有效字符的个数
for(i=0;i<m;i++)
{
for(j=0;i-j>=0&&i+j<m;j++)
{
if(s[i-j]!=s[i+j])break;
if(j*2+1>max){
max=j*2+1;
x=p[i-j];
y=p[i+j];
}
}
for(j=0;i-j>=0&&i+j+1<m;j++)
{
if(s[i-j]!=s[i+j+1])break;
if(j*2+2>max){
max=j*2+2;
x=p[i-j];
y=p[i+j+1];
}
}
}
for(i=x;i<=y;i++)
{
printf("%c",buf[i]);
}
printf("%s",s);
return 0;
}