⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ffffff.cpp

📁 求最简合一的程序
💻 CPP
字号:
#include<stdio.h>
#include<malloc.h>
#include<string.h>

#define NIL "\n"
#define FAIL 0
const int TRUE=1;
const int FALSE=0;

int is_atmo(char*);
//void change(char*,char*);
int is_equal(char*,char*);
int is_varible(char*);
int is_appear(char*,char*);
char*getfirst(char*,char*);
char* replace(char*,char,char);
char*Union(char*,char*);

char*UNIFY(char*,char*);

void main()
{
    char *E1=(char*)malloc(5*sizeof(char));
    char *E2=(char*)malloc(5*sizeof(char));
//    printf("清输入E1,形式为:x,A,B,z\n");
 //   scanf("%c,%c,%c,%c",E1,E1+1,E1+2,E1+3);
    printf("请输入E1,形式为:xABz\n");
    scanf("%s",E1);
    *(E1+4)='\0';
    printf("请输入E2,形式为:Bxyz\n");
   // scanf("%c,%c,%c,%c",E2,E2+1,E2+2,E2+3);
    scanf("%s",E2);
    *(E2+4)='\0';
   printf("%s",UNIFY(E1,E2));

}
int is_atmo(char* E)
{
    if(*(E+1)=='\0')
        return TRUE;
    else
        return FALSE;
}
/*
void change(char*e1,char*e2)
{
    int i=0;
    char c;
    while((*e1+i)!='\0')
    {
        c=*(e1+i);
        *(e1+i)=*(e2+i);
        *(e2+i)=c;
        i++;
    }
}*/
int is_equal(char *e1,char *e2)
{
    if(*e1==*e2)
        return TRUE;
    else
        return FALSE;
}
int is_varible(char *c)
{
    if((*c)>=97&&(*c)<=122)
        return TRUE;
    else
        return FALSE;
}
int is_appear(char *e1,char *e2)
{
    if(!strstr(e1,e2))
        return FALSE;
    else
        return TRUE;
}
char*getfirst(char *e1,char *e2)
{
    char*p2=(char*)malloc(2*sizeof(char));
    char*p=(char*)malloc(4*sizeof(char));
    p=e1+1;
    strcpy(e2,p);
    *p2=*e1;
    *(p2+1)='\0';
    return p2;
}
char* replace(char *e,char c,char a)
{
    int i=0;
    char*p=(char*)malloc(5*sizeof(char));
    p=e;
    while(*(p+i)!='\0')
    {
        if(*(p+i)==a)
            *(p+i)=c;
        i++;
    }
    return p;
}
char*Union(char*Z1,char*Z2)
{
	int i=0,j=0;
if(*Z1=='\n'&&*Z2=='\n')
return "\n";
char*p=(char*)malloc(5*sizeof(char));
    while(*(Z1+i)!='\0'&&*(Z1+i)!='\n')
	{
        *(p+i)=*(Z1+i);
		i++;
	}
    while(*(Z2+j)!='\0'&&*(Z2+j)!='\n')
	{
        *(p+i+j)=*(Z2+j);
		j++;
	}
    *(p+i+j)='\0';
    return p;
}
char*UNIFY(char *E1,char *E2)
{    
    char *T1=(char*)malloc(10*sizeof(char));
    char *T2=(char*)malloc(10*sizeof(char));
    char *G1=(char*)malloc(10*sizeof(char));
    char *G2=(char*)malloc(10*sizeof(char));
    char *Z1=(char*)malloc(10*sizeof(char));
    char *Z2=(char*)malloc(10*sizeof(char));
    char *F1=(char*)malloc(2*sizeof(char));
    char *F2=(char*)malloc(2*sizeof(char));
    char *res=(char*)malloc(10*sizeof(char));
   // if(is_atmo(E2))
   //     change(E1,E2);
    if(is_atmo(E1))
    {
        if(is_equal(E1,E2))
            return NIL;
        if(is_varible(E1))
        {
            if(is_appear(E2,E1))
                return FAIL;
            *res=*E2;
            *(res+1)='\\';
            *(res+2)=*E1;
            *(res+3)='\0';
            return res;
        }
        if(is_varible(E2))
        {
            *res=*E1;
            *(res+1)='\\';
            *(res+2)=*E2;
            *(res+3)='\0';
            return res;
        }
            return FAIL;
    }

    F1=getfirst(E1,T1);
    F2=getfirst(E2,T2);
    Z1=UNIFY(F1,F2);
    if(Z1==FAIL)
        return FAIL;
    G1=replace(T1,*Z1,*(Z1+2));
    G2=replace(T2,*Z1,*(Z1+2));
    Z2=UNIFY(G1,G2);
    if(Z2==FAIL)
        return FAIL;
    return Union(Z1,Z2);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -