| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 438 人关注过本帖
标题:学c两个多月了,这是我写的用来解决实际问题的最长的程序,还不完善,明天接 ...
只看楼主 加入收藏
xdh0817
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:193
专家分:195
注 册:2011-10-20
结帖率:92.86%
收藏
已结贴  问题点数:10 回复次数:1 
学c两个多月了,这是我写的用来解决实际问题的最长的程序,还不完善,明天接着写,感觉自己的代码垃圾,好的代码应该写不了这么长,哪里写的很差,希望大家指出来,谢谢~
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void ling(char *p)
{   char *mk;
    mk=p;
    memset(mk,0,100);
}
void main()
{   FILE *fp,*fp1,*fp2,*fp4,*fp5,*fp6;
    unsigned long y6,t8,as,p9,k=1,ppp=0,i,t1=1,qqq=0,u,s,m,oop=0,nu=0,hang=0;
    __int64 y5=0;
    char ch,ch1;
    char a[100],b[100],c[100],d[100],e[100],f[100],g[100];
    char *ao,*bo,*co;
    char *z1,*z2,*z3,*z4,*z5,*z6,*z7;
    ao=a;bo=b,co=c;z4=d;z5=e;z6=f;z7=g;
    printf("        input your original txt   (example:xdh.txt):   ");
    gets(d);
    printf("        input you r line txt name (example:xdh.txt):   ");
    gets(g);
    printf("        input your test  txt name (example :xdh.txt):   ");
    gets(e);
    printf("        input your number txt name (example:xdh.txt):   ");
    gets(f);
 fp=fopen(z4,"r");
 fp6=fopen(z7,"w");
 ch=fgetc(fp);
 while(ch!=';')
 {
   fputc(ch,fp6);
   ch=fgetc(fp);
 }
 fputc('\t',fp6);
 nu++;
 ch=fgetc(fp);
 while(ch!='\n')
 ch=fgetc(fp);
 ch=fgetc(fp);
 while(ch!=EOF)
 {while(ch!=';')
   {
   fputc(ch,fp6);
   ch=fgetc(fp);
   }
 fputc('\t',fp6);
 nu++;
 ch=fgetc(fp);
 while(ch!='\n')
 ch=fgetc(fp);
 ch=fgetc(fp);
}
fclose(fp);
fclose(fp6);   
printf("%d\n",nu);   
    fp=fopen(z4,"r");
    fp1=fopen(z5,"w");
do
{   
    if(ppp==0)
  {
        ch=fgetc(fp);
        while(ch!=';')
        ch=fgetc(fp);
       ch=fgetc(fp);
      y6=0;t8=0;as=0;
   while(ch!=';')
   {   
          a[y6++]=ch;
       ch=fgetc(fp);
   }
   a[y6]=0;
   y6=0;t8=0;as=0;
   for(y6=0;y6<strlen(a);y6++)
   if(a[y6]==',') {t8++; as=y6;}
   if(t8>=1&&a[as+1]>='0'&&a[as+1]<='9')
   {  
       for(y6=0;y6<as;y6++)
        fputc(a[y6],fp1);
    y5++;
   }  
   ling(ao);
   fputc('\t',fp1);
   fclose(fp1);
   ch=fgetc(fp);
   while(ch!='\n')   
           { y6=0;as=0;t8=0;
             while(ch!=';')
             {  
                 a[y6++]=ch;
                 ch=fgetc(fp);
             }
             a[y6]=0;
             for(y6=0;y6<strlen(a);y6++)
             if(a[y6]==',')
             {
                 t8++;
                 as=y6;
             }
             if(t8>=1&&a[as+1]>='0'&&a[as+1]<='9')
            {  
                for(y6=0;y6<as;y6++)
                 c[y6]=a[y6];
                  y5++;
                  p9=0;
                  fp2=fopen(z5,"r");
                  ch=fgetc(fp2);
                  y6=0;
                  while(ch!=EOF)
                  {
                    if(ch!='\t')
                    {
                        b[y6++]=ch;
                        ch=fgetc(fp2);
                    }
                    else
                       {  b[y6]=0;
                             if(strcmp(c,b)!=0)
                              {  p9++; y6=0;  ling(bo);   
                                 ch=fgetc(fp2);
                              }                  
                          else
                          {  
                              ling(bo);
                              break;
                          }
                       }
                     
                  }
                 if(p9==k)
                        {    fclose(fp2);
                               fp2=fopen(z5,"a");
                               for(y6=0;y6<as;y6++)
                                  fputc(c[y6],fp2);
                               fputc('\t',fp2);
                               fclose(fp2);
                               k++;
                              
                        }
                else fclose(fp2);               
            }  
           ling(ao);
           ling(co);
           ch=fgetc(fp);
           }
           ppp=1;
  }
  else
     {  fseek(fp,-1L,1);
         ch=fgetc(fp);
        while(ch!=';')
        ch=fgetc(fp);
       ch=fgetc(fp);
         while(ch!='\n')  
           { y6=0;as=0;t8=0;p9=0;
             while(ch!=';')
             {  
                 a[y6++]=ch;
                 ch=fgetc(fp);
             }
                a[y6]=0;
             for(y6=0;y6<strlen(a);y6++)
             if(a[y6]==',') {t8++; as=y6;}
             if(t8>=1&&a[as+1]>='0'&&a[as+1]<='9')
            {  
                for(y6=0;y6<as;y6++)
                 c[y6]=a[y6];
                  y5++;
                  p9=0;
                  fp2=fopen(z5,"r");
                  ch=fgetc(fp2);
                  y6=0;
                  while(ch!=EOF)
                  {
                    if(ch!='\t')
                    {
                        b[y6++]=ch;
                        ch=fgetc(fp2);
                    }
                    else
                       {  b[y6]=0;
                             if(strcmp(c,b)!=0)
                              {  p9++; y6=0;  ling(bo);   
                                 ch=fgetc(fp2);
                              }                  
                          else
                          {  
                              ling(bo);
                              break;
                          }
                       }
                     
                  }
                 if(p9==k)
                        {    fclose(fp2);
                               fp2=fopen(z5,"a");
                               for(y6=0;y6<as;y6++)
                                  fputc(c[y6],fp2);
                               fputc('\t',fp2);
                               fclose(fp2);
                               k++;
                        }
                else fclose(fp2);
             }  
           ling(ao);
           ling(co);
           ch=fgetc(fp);
           }
           ppp=1;
     }
     if(y5%5==0)
     {
     printf("            ***has completed %ld,",y5);
     printf("different kinds :%ld\n",k);
     }
     ch=fgetc(fp);
}while(ch!=EOF);
  fclose(fp);
  printf("            total lines :%ld,total kinds %ld,",nu,y5);   
   printf("total different: %ld\n",k);
   z1=a;z2=b;z3=c;
   fp=fopen(z4,"r");
   fp4=fopen(z5,"r");
   fp5=fopen(z6,"w");
   ch1=fgetc(fp4);
 do
 {
   i=0;
   while(ch1!='\t')
   {
    b[i++]=ch1;
    ch1=fgetc(fp4);
   }
   b[i]=0;   
    ch1=fgetc(fp);
   while(ch1!='\n')
   {     i=0;
          u=0;s=0;m=0;
      if(t1==1)
        {
            while(ch1!=';')
            ch1=fgetc(fp);
            ch1=fgetc(fp);
        while(ch1!=';')
        {   
               a[u++]=ch1;
            ch1=fgetc(fp);
        }
       a[u]=0;
       u=0;s=0;m=0;
       for(u=0;u<strlen(a);u++)
       if(a[u]==',') {s++; m=u;}
       if(s>=1&&a[m+1]>='0'&&a[m+1]<='9')
       {  
         for(u=0;u<m;u++)
              c[i++]=a[u];
              c[i]=0;
       }
     if(strlen(c)!=0)
       {  
           if(strcmp(b,c)==0)  
             {
                 for(u=m+1;u<strlen(a);u++)
                 fputc(a[u],fp5);
                 fputc('\t',fp5);
                 t1=1;
                 rewind(fp);
                 break;
             }
             else {ch1=fgetc(fp);ling(z1);ling(z3);t1=0; }
      }
     else {t1=0;ch1=fgetc(fp);}
    }
   else
    {
            while(ch1!=';')
        {   
               a[u++]=ch1;
            ch1=fgetc(fp);
        }
        a[u]=0;
       u=0;s=0;m=0;
       for(u=0;u<strlen(a);u++)
       if(a[u]==',') {s++; m=u;}
       if(s>=1&&a[m+1]>='0'&&a[m+1]<='9')
       {  
         for(u=0;u<m;u++)
              c[i++]=a[u];
              c[i]=0;
       }
     if(strlen(c)!=0)
       {  
           if(strcmp(b,c)==0)  
             {
                 for(u=m+1;u<strlen(a);u++)
                 fputc(a[u],fp5);
                 fputc('\t',fp5);
                 t1=1;
                 rewind(fp);
                 break;
             }
             else {ch1=fgetc(fp);ling(z1);ling(z3);t1=0; }
      }
     else {t1=0;ch1=fgetc(fp);}
     }
   }
   if(t1==0)
   {
        fputc('0',fp5);
        fputc('\t',fp5);
        rewind(fp);
   }
   ling(z1);ling(z2);ling(z3);
   ch1=fgetc(fp4);
 }while(ch1!=EOF);
 putc('\n',fp5);
 hang++;
rewind(fp4);
if(oop==1) {fseek(fp,-1L,1);}
   ch=fgetc(fp);
  while(ch!='\n')
  ch=fgetc(fp);   
  ch=fgetc(fp4);
 do
 {
   i=0;
   while(ch!='\t')
   {
    b[i++]=ch;
    ch=fgetc(fp4);
   }
   b[i]=0;
   ch=fgetc(fp);
   while(ch!='\n')
   {     i=0;
          u=0;s=0;m=0;
      if(t1==1)
        { while(ch!=';')
         ch=fgetc(fp);
         ch=fgetc(fp);
        while(ch!=';')
        {   
               a[u++]=ch;
            ch=fgetc(fp);
        }
        a[u]=0;
       u=0;s=0;m=0;
       for(u=0;u<strlen(a);u++)
       if(a[u]==',') {s++; m=u;}
       if(s>=1&&a[m+1]>='0'&&a[m+1]<='9')
       {  
         for(u=0;u<m;u++)
              c[i++]=a[u];
              c[i]=0;
       }
     if(strlen(c)!=0)
       {  
           if(strcmp(b,c)==0)  
             {
                 for(u=m+1;u<strlen(a);u++)
                 fputc(a[u],fp5);
                 fputc('\t',fp5);
                 t1=1;
                 fseek(fp,-2L,1);
              ch=fgetc(fp);
             while(ch!='\n')
             {
               fseek(fp,-2L,1);
               ch=fgetc(fp);
             }
                 break;
             }
             else {ch=fgetc(fp);ling(z1);ling(z3);t1=0; }
      }
     else {t1=0;ch=fgetc(fp);}
    }
   else
    {
            while(ch!=';')
        {   
               a[u++]=ch;
            ch=fgetc(fp);
        }
        a[u]=0;
       u=0;s=0;m=0;
       for(u=0;u<strlen(a);u++)
       if(a[u]==',') {s++; m=u;}
       if(s>=1&&a[m+1]>='0'&&a[m+1]<='9')
       {  
         for(u=0;u<m;u++)
              c[i++]=a[u];
              c[i]=0;
       }
     if(strlen(c)!=0)
       {  
           if(strcmp(b,c)==0)  
             {
                 for(u=m+1;u<strlen(a);u++)
                 fputc(a[u],fp5);
                 fputc('\t',fp5);
                 t1=1;
                 fseek(fp,-2L,1);
              ch=fgetc(fp);
             while(ch!='\n')
             {
               fseek(fp,-2L,1);
               ch=fgetc(fp);
             }
                 break;
             }
             else {ch=fgetc(fp);ling(z1);ling(z3);t1=0; }
      }
     else {t1=0;ch=fgetc(fp);}
     }
  }
   if(t1==0) {
                    fputc('0',fp5); fputc('\t',fp5);
                    fseek(fp,-3L,1);
                 ch=fgetc(fp);
                 while(ch!='\n')
                 {
                   fseek(fp,-2L,1);
                   ch=fgetc(fp);
                 }
                  }
   ling(z1);ling(z2);ling(z3);
   ch=fgetc(fp4);
   oop=1;
}while(ch!=EOF);
 putc('\n',fp5);
 hang++;
 ch=fgetc(fp);
 while(ch!='\n')
 {
 ch=fgetc(fp);   
 }
 ch=fgetc(fp);
 rewind(fp4);
  while(ch!=EOF)
  { fseek(fp,-1L,1);
    ch=fgetc(fp4);
 do
 {
   i=0;
   while(ch!='\t')
   {
    b[i++]=ch;
    ch=fgetc(fp4);
   }
   b[i]=0;
  ch=fgetc(fp);
   while(ch!='\n')
   {     i=0;
          u=0;s=0;m=0;
      if(t1==1)
        {
            while(ch!=';')
             ch=fgetc(fp);
            ch=fgetc(fp);
            while(ch!=';')
          {   
               a[u++]=ch;
            ch=fgetc(fp);
          }
        a[u]=0;
        u=0;s=0;m=0;
       for(u=0;u<strlen(a);u++)
       if(a[u]==',') {s++; m=u;}
       if(s>=1&&a[m+1]>='0'&&a[m+1]<='9')
       {  
         for(u=0;u<m;u++)
              c[i++]=a[u];
              c[i]=0;
       }
     if(strlen(c)!=0)
       {  
           if(strcmp(b,c)==0)  
             {
                 for(u=m+1;u<strlen(a);u++)
                 fputc(a[u],fp5);
                 fputc('\t',fp5);
                 t1=1;
                 fseek(fp,-2L,1);
              ch=fgetc(fp);
             while(ch!='\n')
             {
               fseek(fp,-2L,1);
               ch=fgetc(fp);
             }
                 break;
             }
             else {ch=fgetc(fp);ling(z1);ling(z3);t1=0; }
      }
      else {t1=0;ch=fgetc(fp);}
     }
    else
     {
             while(ch!=';')
         {   
               a[u++]=ch;
            ch=fgetc(fp);
         }
        a[u]=0;
       u=0;s=0;m=0;
        for(u=0;u<strlen(a);u++)
        if(a[u]==',') {s++; m=u;}
        if(s>=1&&a[m+1]>='0'&&a[m+1]<='9')
        {  
          for(u=0;u<m;u++)
              c[i++]=a[u];
              c[i]=0;
        }
        if(strlen(c)!=0)
          {  
              if(strcmp(b,c)==0)  
                {
                    for(u=m+1;u<strlen(a);u++)
                    fputc(a[u],fp5);
                    fputc('\t',fp5);
                    t1=1;
                    fseek(fp,-2L,1);
                 ch=fgetc(fp);
                while(ch!='\n')
                {
                  fseek(fp,-2L,1);
                  ch=fgetc(fp);
                }
                    break;
                }
                else {ch=fgetc(fp);ling(z1);ling(z3);t1=0; }
         }
        else
        {
            t1=0;
            ch=fgetc(fp);
        }
     }
  }
   if(t1==0) {
                    fputc('0',fp5);
                    fputc('\t',fp5);
                    fseek(fp,-3L,1);
                 ch=fgetc(fp);
                 while(ch!='\n')
                 {
                   fseek(fp,-2L,1);
                   ch=fgetc(fp);
                 }
                }
   ling(z1);ling(z2);ling(z3);
   ch=fgetc(fp4);
   oop=1;
}while(ch!=EOF);
 putc('\n',fp5);
 hang++;
 ch=fgetc(fp);
 while(ch!='\n')
 {
  ch=fgetc(fp);   
 }
 ch=fgetc(fp);
 rewind(fp4);
 printf("has completed %ld\n",hang);
 }
fclose(fp);
fclose(fp5);
fclose(fp4);
getchar();
}
搜索更多相关主题的帖子: original example include 
2011-12-08 02:39
embed_xuel
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:58
帖 子:3845
专家分:11385
注 册:2011-9-13
收藏
得分:10 
回复 楼主 xdh0817
没注释,谁会看啊

总有那身价贱的人给作业贴回复完整的代码
2011-12-08 07:07
快速回复:学c两个多月了,这是我写的用来解决实际问题的最长的程序,还不完善, ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022704 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved