英文文章顺序还原

时间:2008-05-13 05:39:36   来源:论坛整理  作者:  编辑:chinaitzhe
原文【Abclmvba duh iwfbs jvsq b chyplaf qh ikilmuqk mlnvrczfyod. Kv ku
cqnanoxan nbbnwcrju vq nbcjkurbq b yeyzks iru ymjnw nmdljcrxw bmnhm
ampp pqqpnetgpwj gtyckx sxnsfsnekv sjjix. Kv ampp lipt abclmvba vq
klclsvw ymjnw rtwfq xjsxj, ymjnw mbokdsfsdi, dqg ymjnw yajlcrlju
jkrurcrnb. Cv wkh weqi xmqi, kv ku wnlnbbjah iru wkh exsfobcsdi vq
nwlxdajpn ildivkml zmamizkp kp qerc lokrjy. B gfxnh jvujlyu ampp dg vq
ykiaxk myllkvt qh zmamizkp bmnqj mvaczqvo xlex wkh ylzbsaz qh zmamizkp
duh mrbluxbnm.】
——————————————————————————
我已经找到这片英文的规律,请大家帮我想想应该如何编程。
规律:
当字符串只有一个字母时,例如b,它应向前一位,是a
当字符串只有两个字母时,例如vq,它的每一个字母应向前两位,是to
当字符串只有3个字母时,例如wkh,它的每一个字母应向前3位,是the
以次类推

我的程序编到一半就没有头绪了,清高手指教

#include <stdio.h>

int StrLength (const char *s)
char *permute_str(const *a[20])
main()
{
FILE *fp;
int chk;
char a[10000],fname[256],sstr[100];
printf("fname : ");
scanf("%s",fname);

if( (fp=fopen(fname,"r"))==NULL){
printf("do not open it\n",fname);return;
}
while((c = getc(fname))!= EOF)
}

int StrLength (const char *s)
{
int n=0;
while (*s !=' ')
n ;
return (n);
}

char *permute_str(const *a[20])
{

if(!isspace(*a[20])){
for(i=0;i <20;i ){
a[i]-(i 1);
printf("%c",str[i]);
i ;
}
}
}

网友回复:只说算法:

定义两个函数
一个函数用来读取字符串,将字符串中的单词以空格为分隔,一个一个读到一个二维数组中
第二个函数用来处理这些单词,应该很简单吧,先用STRLEN算大小,然后一个循环就OK了
网友回复:出这题的人挺BT的
网友回复:不好意思,忘了写"不可用字符串函数"
网友回复:算法都有了还不好写吗?不会用到字符串库函数
网友回复:那就是考你在不用字符串库函数的情况下,怎么解决字符串操作问题。
网友回复:大侠提示一下,我现在没有头绪。
网友回复:
引用 1 楼 PcrazyC 的回复:
只说算法:

定义两个函数
一个函数用来读取字符串,将字符串中的单词以空格为分隔,一个一个读到一个二维数组中
第二个函数用来处理这些单词,应该很简单吧,先用STRLEN算大小,然后一个循环就OK了


就用这种方法就可以
网友回复:那么A,B,C,a,b,c怎么处理,也是向前
假如是AB,也是向前两个么,那就不是字母了。。。
网友回复:算法有道理,但是我觉得并不是这么简单
网友回复:给LZ参考,但是没有考虑到标点符号,结果看着有点怪,但还是有点英文原文的样子
C/C code





Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/





#include<iostream>

#include<fstream>

using namespace std;



int main() {

    char words[256][20];

    int i = 0;

    ifstream in("test.txt");

    

    while(in >> words[i]) {

        i  ;    //获取了有多少个单词

    }

    

    for(int j = 0; j < i; j  ){

        for(int k = 0; words[j][k] != '\0';k  );    //获取每一个单词的长度

        

        for(int l = 0; l < k; l  ) {    //将每一个单词转换

            words[j][l] -= k;

        }

    }

    

    for(j = 0; j < i; j  ) {    //输出

        cout << words[j] << ' ';

    }

    cout << endl;

}

/* 输出结果

9Z[denZY are dra]n from a \arieZ_ of academic a`bjfWnZmcX" It is ZheXefoXe eYYen

Zial to eYZabliYh a s_stem for their ed[caZion ]hich ]ill effecZi\el_ ans]er ind

i\id[al mddcr( It ]ill help YZ[denZY to de\elop their moral rdmrd& their bWd`Yh[

hY^! and their pXacZical `ahkhYhdX$ At the same shld' it is neceYYaX_ for the [n

i\eXYiZ_ to enco[Xage ad\anced reYearch in man_ ehdkcr' A basic concern ]ill be

to sec[re freedom of reYearch ]hile enY[ring that the res[lZs of reYearch are ch

XbknXdc$

*/




网友回复:
C/C code





Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/



#include <stdio.h> 

#include<stdlib.h>



void Str_Change(char *ch,int n)

{

    if(*ch>='A'&&*ch<='Z')

        *ch=(*ch-n-'A')& 'A';

    else

        if(*ch>='a'&&*ch<='z')

            *ch=(*ch-n-'a' 26)& 'a';

}

int StrLength (const char *str) 

{ 

    int n=0; 

    while(*str  ) 

        n  ; 

    return n; 

} 



void permute_str(char *str) 

{ 

    int n=StrLength(str);

    while(*str)

        Str_Change(str  ,n);



} 



int main() 

{ 

    FILE *fp; 

    char str[1000][30]={0},fname[50];

    printf("fname: "); 

    scanf("%s",fname); 

    int i=0,j;

    if( (fp=fopen(fname,"r"))==NULL)

    { 

        printf("do not open it\n",fname); 

        exit(0);

    } 

    while(!feof(fp))

        fscanf(fp,"%s",str[i  ]);

    for(j=0;j<i;j  )

        permute_str(str[j]);

    for(j=0;j<i;j  )

        printf("%s\t",str[j]);

    return 0;

} 






网友回复: 学习学习
网友回复:大写字母那忘记加26了,改一下


C/C code





Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/



#include <stdio.h> 

#include<stdlib.h>



void Str_Change(char *ch,int n)

{

    if(*ch>='A'&&*ch<='Z')

        *ch=(*ch-n-'A' 26)& 'A';

    else

        if(*ch>='a'&&*ch<='z')

            *ch=(*ch-n-'a' 26)& 'a';

}

int StrLength (const char *str) 

{ 

    int n=0; 

    while(*str  ) 

        n  ; 

    return n; 

} 



void permute_str(char *str) 

{ 

    int n=StrLength(str);

    while(*str)

        Str_Change(str  ,n);



} 



int main() 

{ 

    FILE *fp; 

    char str[1000][30]={0},fname[50];

    printf("fname: "); 

    scanf("%s",fname); 

    int i=0,j;

    if( (fp=fopen(fname,"r"))==NULL)

    { 

        printf("do not open it\n",fname); 

        exit(0);

    } 

    while(!feof(fp))

        fscanf(fp,"%s",str[i  ]);

    for(j=0;j<i;j  )

        permute_str(str[j]);

    for(j=0;j<i;j  )

        printf("%s\t",str[j]);

    return 0;

} 






网友回复:感觉中间可能某些地方因为空格问题出了问题,程序应该是没有问题的

C/C code





Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/



Students        are     drawn   from    a       variety of      academic

azbjfqntmcr.    It      is      therefore       essential       to      establis

h       a       system  for     their   evdbujpo        which   will    effectiv

ely     answer  individual      mddcr.  It      will    help    students

to      develop their   moral   rdmrd,  their   bqdzshuhsx,     and     their

practical       zahkhshdr.      At      the     same    shld,   it      is

necessary       for     the     university      to      encourage       advanced

        research        in      many    ehdkcr. A       basic   concern will

be      to      secure  freedom of      research        while   ensuring

that    the     results of      research        are     disclosed


网友回复://算了一下,你的编码还是错误滴,根本解不出来赫赫,但是代码还是没问题滴
C/C code





Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/



#include "stdio.h"







int main()

{

   FILE *pread;

   FILE *pwrite;

   char c,buf[100]={0},i,Len=0;

   

   pread = fopen("ss.txt","r");

   if(NULL == pread)printf("pread\n");

   

   pwrite = fopen("tt.txt","w ");

   if(NULL == pwrite)printf("pwrite\n");

   

   while( (c=fgetc(pread)) != EOF )

   {

     if(c==' ')

     {

       if(!Len)

         continue;   

       for(i=0;i<Len;i  )

         buf[i]=buf[i]-Len;

       buf[Len]=0;

       fprintf(pwrite,"%s ",buf);

       

       Len=0;

       continue;

     }

     

     buf[Len  ]=c;          

   }

   

   fclose(pread);

   fclose(pwrite);

   

   return 0;

}


网友回复:哦,我知道了,是因为标点符号的问题,我还没有处理这个........
网友回复:9Z[denZY are dra]n from a \arieZ_ of academic a`bjfWnZmcX" It is eYYenZial to eYZabliYh a s_stem for their ed[caZion ]hich \hkk effecZi\el_ ans]er indi\id[al mddcr( It ]ill help YZ[denZY to cd[dkno their moral rdmrd& their bWd`Yh[hY^! and their pXacZical
关键字:英文,文章,顺序,还原,

文章评论

共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面