Differences between revisions 5 and 6
Revision 5 as of 2005-04-02 06:38:10
Size: 2954
Editor: hoxide
Comment:
Revision 6 as of 2005-04-02 06:41:52
Size: 4058
Editor: hoxide
Comment:
Deletions are marked like this. Additions are marked like this.
Line 6: Line 6:

---- /!\ '''Edit conflict - other version:''' ----
::-- hoxide [[[DateTime(2005-04-02T06:32:37Z)]]]

---- /!\ '''Edit conflict - your version:''' ----
::-- hoxide [[[DateTime(2005-04-02T06:38:10Z)]]]

---- /!\ '''End of edit conflict''' ----
Line 18: Line 10:


---- /!\ '''Edit conflict - other version:''' ----
Line 25: Line 14:

---- /!\ '''Edit conflict - your version:''' ----
Line 141: Line 128:


---- /!\ '''Edit conflict - other version:''' ----

---- /!\ '''Edit conflict - your version:''' ----

---- /!\ '''End of edit conflict''' ----
Line 150: Line 130:
==== 次节标题1 ====
xxx
==== 某题 ====
{{{
#!cplusplus

#include<stdio.h>
#include<string.h>
typedef struct
{ char ch[50];
   int len;
}SqString;
int creat_string(SqString s1,SqString s2,SqString s);
int check(int a[50][50]);


void main()
{ int i=0;
   SqString s,s1,s2;
   scanf("%s",&s1.ch);
   s1.len=strlen(s1.ch);
   scanf("%s",&s2.ch);
   s2.len=strlen(s2.ch);
   for(i=0;i<10;i++){

   s.ch[i]='*';
 s.len++;
   }
   creat_string(s1,s2,s);
   return ;
}
int creat_string(SqString s1,SqString s2,SqString &s)
{ int i,j,k,m,n,t=0;
   int a[50][50];
   int b[50][50];
   for(i=0;i<50;i++)
    for(j=0;j<50;j++)
           a[i][j]=b[i][j]=0;
   for(i=0;i<s1.len;i++)
    for(j=0;j<s2.len;j++)
     if(s1.ch[i]==s2.ch[j])
      a[i][j]=1;
   k=1;
   while(check(a))
   {
   for(i=0;i<s1.len;i++)
        for(j=0;j<s2.len;j++)
  {
        b[i][j]=a[i][j];
  }
   for(m=0;m<s1.len;m++)
   { while(i<s1.len&&j<s2.len)
   { if(a[i][j]==1&&a[i+k][j+k]==0)
   { a[i][j]=0;
             i=i+k+1;
    j=j+k+1;
   }
         else
   {i++;
    j++;
   }
   }
   }
   for(n=0;n<s2.len;n++)
   { while(i<s1.len&&j<s2.len)
   { if(a[i][j]==1&&a[i+k][j+k]==0)
   { a[i][j]=0;
             i=i+k+1;
    j=j+k+1;
   }
         else
   {i++;
    j++;
   }
   }
   }
   k++;
 }
 while(i<s1.len&&j<s2.len)
   if(b[i][j]==1)
    for(;t<k;t++)
    { s.ch[t]=s1.ch[i];
      i++;
    }
 printf("%s",s.ch);
 return 1;
}
int check(int a[50][50])
{ int i,j;
  for(i=0;i<50;i++)
        for(j=0;j<50;j++)
   if(a[i][j]!=0)
    return 1;
  return 0;
}

...
}}}

含有章节索引的中文 文章模板

TableOfContents

文章大标

简述

章标题1

小节标题1

   1 === 小节标题1 ===
   2 {{{
   3 #!cplusplus
   4 
   5 
   6 ---- /!\ '''End of edit conflict''' ----
   7 #include <stdio.h>
   8 #include <string.h>
   9 #include <stdlib.h>
  10 
  11 #define TPS 4
  12 
  13 #define STEP                  \
  14  do {                         \
  15    tt =1;                     \
  16    for(; d<TPS; d++)            \
  17    {                          \
  18        tr=r+tp[d][0], tc=c+tp[d][1];         \
  19        if (tr>=0 && tr <n && tc>=0 && tc <m && p[tr][tc]=='.')    \
  20          {  r = tr, c = tc;   \
  21             p[r][c] = '0'+d;    \
  22             st[t] = d;        \
  23             t++, s++;         \
  24             tt  = 0;           \   
  25             break;             \
  26          }                     \                
  27    }                           \
  28 } while(0)
  29      
  30      
  31 #define  OMAX  25
  32 
  33 void printp(int n, int m, char **p)
  34 {
  35   int i, j;
  36   fprintf(stdout, "\n");
  37   for(i=0; i<n; i++)
  38   {
  39     for(j=0; j<m; j++)
  40       fprintf(stdout, "%c", p[i][j]);
  41     fprintf(stdout, "\n");
  42   }
  43 }
  44 
  45 int count(int n, int m, char **p)
  46 {
  47   int st[OMAX*OMAX];
  48   int s, d;
  49   int tt;
  50   signed int t;
  51   signed int r, c, tr, tc;
  52   int tp[TPS][2] = { {+1, 0}, {-1, 0}, {0, +1}, {0, -1} };
  53   //printp(n,m,p);
  54   for(r=0; r<n; r++)
  55     {
  56       for(c=0; c<m; c++)
  57         if(p[r][c]=='@')
  58           break;
  59       if(p[r][c]=='@')
  60         break;
  61     }
  62   for(s=1, st[0]=TPS, t=1; t>0;)
  63     {
  64       d=0;
  65       STEP;
  66       //fprintf(stderr, "(%d, %d)\t", r, c);
  67       //printp(n,m,p);
  68 
  69       while (t>0 && tt == 1) 
  70         {
  71           t--;
  72           d = st[t];
  73           r -= tp[d][0];
  74           c -= tp[d][1];
  75           d++;
  76           STEP;
  77           //fprintf(stderr, "(%d, %d)\t", r, c);
  78         }
  79     }
  80   return s;
  81 }
  82 
  83 int pp(char **p)
  84 {
  85   int n, m;
  86   int i;
  87   fscanf(stdin, "%d%d", &m, &n);
  88   for(i=0; i<n ;i++)
  89     fscanf(stdin,"%s", p[i]);
  90 
  91   if(n==0 || m==0)
  92     return 0;
  93   else
  94     return count(n, m, p);
  95 }
  96 
  97 int main()
  98 {
  99   int i;
 100   char **p;
 101   p = (char **)malloc(sizeof(char*)*OMAX);
 102   for(i=0; i< OMAX; i++)
 103     p[i]=(char *)malloc(sizeof(char)*OMAX);
 104   do
 105     {
 106       i=pp(p);
 107       if(i!=0)
 108         fprintf(stdout, "%d\n", i);
 109     }
 110   while(i!=0);
 111 
 112   return 0;
 113 }

某题

   1 #include<stdio.h>
   2 #include<string.h>
   3 typedef struct 
   4 {  char ch[50];
   5    int len;
   6 }SqString;
   7 int creat_string(SqString s1,SqString s2,SqString s);
   8 int check(int a[50][50]);
   9 
  10 
  11 void main()
  12 {  int i=0;
  13    SqString s,s1,s2;
  14    scanf("%s",&s1.ch);
  15    s1.len=strlen(s1.ch); 
  16    scanf("%s",&s2.ch);
  17    s2.len=strlen(s2.ch);
  18    for(i=0;i<10;i++){
  19 
  20    s.ch[i]='*';
  21         s.len++;
  22    }
  23    creat_string(s1,s2,s);
  24    return ;
  25 }
  26 int creat_string(SqString s1,SqString s2,SqString &s)
  27 {  int i,j,k,m,n,t=0;
  28    int a[50][50];
  29    int b[50][50];
  30    for(i=0;i<50;i++)
  31            for(j=0;j<50;j++)
  32            a[i][j]=b[i][j]=0;
  33    for(i=0;i<s1.len;i++)
  34            for(j=0;j<s2.len;j++)
  35                    if(s1.ch[i]==s2.ch[j])
  36                            a[i][j]=1;
  37    k=1;
  38    while(check(a))
  39    {
  40           for(i=0;i<s1.len;i++)
  41         for(j=0;j<s2.len;j++)
  42                 {
  43                b[i][j]=a[i][j];
  44                 }
  45           for(m=0;m<s1.len;m++)
  46           {   while(i<s1.len&&j<s2.len)
  47           {     if(a[i][j]==1&&a[i+k][j+k]==0)
  48           {         a[i][j]=0;
  49                     i=i+k+1;
  50                                 j=j+k+1;
  51           }
  52                 else
  53                         {i++;
  54                          j++;
  55                         }
  56           }
  57           }
  58           for(n=0;n<s2.len;n++)
  59           {   while(i<s1.len&&j<s2.len)
  60           {     if(a[i][j]==1&&a[i+k][j+k]==0)
  61           {         a[i][j]=0;
  62                     i=i+k+1;
  63                                 j=j+k+1;
  64           }
  65                 else
  66                         {i++;
  67                          j++;
  68                         }
  69           }
  70           }
  71           k++;
  72         }
  73         while(i<s1.len&&j<s2.len)
  74                         if(b[i][j]==1)
  75                                 for(;t<k;t++)
  76                                 { s.ch[t]=s1.ch[i];
  77                                   i++;
  78                                 }
  79         printf("%s",s.ch);
  80         return 1;
  81 }
  82 int check(int a[50][50])
  83 { int i,j;
  84   for(i=0;i<50;i++)
  85         for(j=0;j<50;j++)
  86                         if(a[i][j]!=0)
  87                                 return 1;
  88   return 0;
  89 }
  90 
  91 ...

章标题2

小节标题2

其它
代码引用

次节标题2

yyy

ACM (last edited 2009-12-25 07:09:54 by localhost)