字符串组合 [英] string combination

查看:61
本文介绍了字符串组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,


以下是我在字母hello中找到所有

组合字母的程序。 br />

#include< stdio.h>

#include< stdlib.h>

#include< string.h>


#define MAX 5

int main(无效)

{

char t [MAX];

int i,j,k,l,m,n = 1;


strcpy(t," hello");


printf(\ n由所有字符组合形成的单词

来自\

单词hello \ $(b = b; i< MAX; i ++)

for(j = 0; j< MAX ; j ++)

{

如果(j == i)

继续;


for (k = 0; k
{

if((k == i)||(k == j))

继续;


for(l = 0; l< MAX; l ++)

{


if((l == i)||(l == j)||(l == k))

继续;


m = 10 - (i + j + k + l);

printf("%c%c%c%c%c" ;,t [i],t [j],t [k],t [l],t [m]);


if(n%10 == 0)puts (");

n ++;

}


}

}


printf(" \ n no:of words formed =%d", - n);


puts("" );

返回EXIT_SUCCESS;

}

可以任何人建议更通用的方法,以便我可以找到

任何输入字符串的字母组合?

解决方案

sophia< so ********** @ gmail.comwrites:


亲爱的,


以下是我为找到所有
$ b所做的计划$ b字符串中的字母组合你好


#include< stdio.h>

#include< stdlib.h>

#include< string.h>


#define MAX 5

int main(void)

{

char t [MAX];

int i,j,k,l,m,n = 1 ;


strcpy(t," hello");


printf(" \ n由所有字符组合形成的单词)

来自\

单词hello \ n \ n");


for(i = 0; i < MAX; i ++)

for(j = 0; j< MAX; j ++)

{

if(j == i)

继续;


for(k = 0; k
{

if((k == i)||(k == j))

继续;


for(l = 0; l< MAX ; l ++)

{


if((l == i)||(l == j)||(l == k))

继续;


m = 10 - (i + j + k + l);

printf("%c%c %c%c%c,t [i],t [j],t [k],t [l],t [m]);


if(n %10 == 0)put("");

n ++;

}


}

}


printf(" \ n no:of words formed =%d", - n);


put("");

返回EXIT_SUCCESS;

}


任何人都可以建议更通用的方法我能找到任何输入字符串的字母组合吗?



首先考虑将它们全部移动到另一个非主要函数

你用你想检查的字符串调用它。这个

" MAX"到处都是可怕的。取而代之的是你的新功能


displayAnagrams(char * s){

int len = strlen(s); / *或size_t ...... * /

....

....

}


至于算法本身,我不知道。


快乐的实验!


< blockquote> sophia写道:


亲爱的,


以下是我为找到所有

字符串中的字母组合hello


#include< stdio.h>

#include< stdlib.h> ;

#include< string.h>


#define MAX 5


int main(void)

{

char t [MAX];

int i,j,k,l,m,n = 1;


strcpy(t," hello");


printf(" \ n由所有字符组合形成的单词

来自\

单词hello \ n \ n");


for(i = 0; i< MAX; i ++)

for(j = 0; j< MAX; j ++)

{

如果(j == i)

继续;


for(k = 0; k< ; MAX; k ++)

{

如果((k == i)||(k == j))

继续;


for(l = 0; l< MAX; l ++)

{


if((l == i)||(l == j)||(l == k))

继续;


m = 10 - (i + j + k + l);

printf("%c%c%c%c%c",t [i],t [j],t [k],t [l],t [m]);


if(n%10 == 0)puts("");

n ++;

}


}

}


printf(" \ n no:of words formed = %d", - n);


puts("");

返回EXIT_SUCCESS;

}


任何人都可以建议一个更通用的方法,以便我可以找到任何输入字符串的字母组合




< http://www.theory.csc.uvic.ca/~cos/inf/perm/PermInfo.html>

< http://c.snippets.org/snip_lister.php?fname = permute2.c>

< http://mathworld.wolfram.com/Permutation.html>

< http://regentsprep.org/Regents/Math/permut/Lperm.htm>


4月15日,6: 17 pm,sophia< sophia.ag ... @ gmail.comwrote:


亲爱的,


以下是我已经完成的程序,找到字符串中的所有字母组合hello


#include< stdio.h>

#include< stdlib.h>

#include< string.h>


#define MAX 5


int main(无效)

{

char t [MAX];

int i,j,k,l ,m,n = 1;


strcpy(t," hello");



t是char [MAX],char [5]。 "你好"由6个元素组成,因此更改



在Google上搜索有关组合和代码的内容。 (不直接与C相关的


Dear all,

The following is the program which i have done to find all the
combination of letters in the string "hello"

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define MAX 5

int main(void)
{
char t[MAX];
int i,j,k,l,m,n=1;

strcpy(t,"hello");

printf("\n words formed from the combinations of all characters
from \
the word hello\n\n");

for(i = 0 ;i < MAX ;i++)
for(j = 0 ;j < MAX ;j++)
{
if(j == i)
continue;

for(k = 0 ;k < MAX ;k++)
{
if( (k==i) || (k == j) )
continue;

for(l = 0 ;l < MAX ;l++)
{

if( (l==i) || (l == j) || (l == k) )
continue;

m = 10 - (i + j + k + l);
printf("%c%c%c%c%c ",t[i],t[j],t[k],t[l],t[m]);

if(n %10 == 0) puts("");
n++;
}

}
}

printf("\n no: of words formed = %d",--n);

puts("");
return EXIT_SUCCESS;
}
can any one suggest a more general method so that i can find the
combination of letters of any inputted string ?

解决方案

sophia <so**********@gmail.comwrites:

Dear all,

The following is the program which i have done to find all the
combination of letters in the string "hello"

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define MAX 5

int main(void)
{
char t[MAX];
int i,j,k,l,m,n=1;

strcpy(t,"hello");

printf("\n words formed from the combinations of all characters
from \
the word hello\n\n");

for(i = 0 ;i < MAX ;i++)
for(j = 0 ;j < MAX ;j++)
{
if(j == i)
continue;

for(k = 0 ;k < MAX ;k++)
{
if( (k==i) || (k == j) )
continue;

for(l = 0 ;l < MAX ;l++)
{

if( (l==i) || (l == j) || (l == k) )
continue;

m = 10 - (i + j + k + l);
printf("%c%c%c%c%c ",t[i],t[j],t[k],t[l],t[m]);

if(n %10 == 0) puts("");
n++;
}

}
}

printf("\n no: of words formed = %d",--n);

puts("");
return EXIT_SUCCESS;
}
can any one suggest a more general method so that i can find the
combination of letters of any inputted string ?

For a start think about moving it all to another "non main" function
where you call it with the string you are interested in checking. This
"MAX" everywhere is horrible. Instead in your new function

displayAnagrams(char *s){
int len = strlen(s); /* or size_t ...... */
....
....
}

As for the algorithm itself, I have no idea.

Happy experimenting!


sophia wrote:

Dear all,

The following is the program which i have done to find all the
combination of letters in the string "hello"

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define MAX 5

int main(void)
{
char t[MAX];
int i,j,k,l,m,n=1;

strcpy(t,"hello");

printf("\n words formed from the combinations of all characters
from \
the word hello\n\n");

for(i = 0 ;i < MAX ;i++)
for(j = 0 ;j < MAX ;j++)
{
if(j == i)
continue;

for(k = 0 ;k < MAX ;k++)
{
if( (k==i) || (k == j) )
continue;

for(l = 0 ;l < MAX ;l++)
{

if( (l==i) || (l == j) || (l == k) )
continue;

m = 10 - (i + j + k + l);
printf("%c%c%c%c%c ",t[i],t[j],t[k],t[l],t[m]);

if(n %10 == 0) puts("");
n++;
}

}
}

printf("\n no: of words formed = %d",--n);

puts("");
return EXIT_SUCCESS;
}
can any one suggest a more general method so that i can find the
combination of letters of any inputted string ?

<http://www.theory.csc.uvic.ca/~cos/inf/perm/PermInfo.html>
<http://c.snippets.org/snip_lister.php?fname=permute2.c>
<http://mathworld.wolfram.com/Permutation.html>
<http://regentsprep.org/Regents/Math/permut/Lperm.htm>


On Apr 15, 6:17 pm, sophia <sophia.ag...@gmail.comwrote:

Dear all,

The following is the program which i have done to find all the
combination of letters in the string "hello"

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define MAX 5

int main(void)
{
char t[MAX];
int i,j,k,l,m,n=1;

strcpy(t,"hello");

t is char[MAX], char[5]. "hello" consists of 6 elements, so change
that.
Search on google about combinations and code. (which are not directly
related to C)


这篇关于字符串组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆