64,637
社区成员
发帖
与我相关
我的任务
分享
// 163.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
static CONST TCHAR Letters[] = TEXT("abcdefghijklmnopqrstuvwxyz");
static CONST INT MAX_COUNT = 26;
static VOID PrintSubRange(INT Begin, INT Length)
{
_tprintf_s(TEXT("("));
INT End = Begin + Length;
for (INT ii=Begin; ii<End; ++ii)
{
_tprintf_s(TEXT("%c,"), Letters[ii]);
}
}
static VOID PrintSubRangeAndAllTail(INT Begin, INT Length)
{
INT End = Begin + Length;
for (INT ii=End; ii<MAX_COUNT; ++ii)
{
PrintSubRange(Begin, Length);
if (ii != MAX_COUNT -1 )
{
_tprintf_s(TEXT("%c), "), Letters[ii]);
}
else
{
_tprintf_s(TEXT("%c) "), Letters[ii]);
}
}
}
static VOID PrintAll()
{
for (INT Length=0; Length<=MAX_COUNT; ++Length)
{
for (INT Begin= 0; Begin < MAX_COUNT - Length; ++Begin)
{
PrintSubRangeAndAllTail(Begin, Length);
if (Length == 0)
{
break;
}
}
_tprintf_s(TEXT("\r\n"));
}
}
int _tmain(int argc, _TCHAR* argv[])
{
PrintAll();
return 0;
}
<?php
$characters=array();
for($i=97;$i<=122;$i++)
$characters[]=chr($i);
$lists=array();
for($k=0;$k<=25;$k++){
$sub_lists=array();
for($i=0;$i<=25-$k;$i++){
$units=array();
if($k==0){
$units[]='('.$characters[$i].')';
}else{
for($j=$i+1;$j<=25-($k-1);$j++){
$items=array();
$items[]=$characters[$i];
for($l=0;$l<=$k-1;$l++){
$items[]=$characters[$j+$l];
}
$units[]='('.implode(',',$items).')';
}
}
$sub_lists[]=implode(',',$units);
}
$lists[]=implode(',',$sub_lists);
}
for($m=0;$m<=25;$m++)
echo $lists[$m].'<br>';
?>
char cs[27];
int csLen=1;
void printCharsTuple(char from,int len)
{
int temp=csLen;
if(len==1)
{
cs[csLen]=from;
csLen++;
cs[csLen]='\0';
cout<<cs<<"),";
}
else
{
cs[csLen]=from;
csLen++;
for(char c=from+1;c<='z';c++)
printCharsTuple(c,len-1);
}
csLen=temp;
}
int main()
{
cs[0]='(';
for(int len=1;len<=26;len++)
{
for(char c='a';c<='z';c++)
printCharsTuple(c,len);
cout<<endl;
}
}