題意很簡(jiǎn)單,寫一個(gè)程序,打印出以下的序列。
(a),(b),(c),(d),(e)........(z)
(a,b),(a,c),(a,d),(a,e)......(a,z),(b,c),(b,d).....(b,z),(c,d).....(y,z)
(a,b,c),(a,b,d)....(a,b,z),(a,c,d)....(x,y,z)
....
(a,b,c,d,.....x,y,z)
code:
#include<iostream>
usingnamespace std;
void func(void)
{
char*table =newchar['z'-'a'+1];
int num;
for (num =1; num <='z'-'a'+1; ++num)
{
int cur =0;
table[0] ='a'-1;
while (cur >=0)
{
table[cur] +=1;
if (table[cur] <='z')
{
if (num -1== cur)
{
int i;
for (i =0; i < num; ++i)
{
cout<<table[i];
}
cout<<", ";
}
else
{
++cur;
table[cur] = table[cur -1];
}
}
else
{
cur -=1;
}
}
cout<<endl;
}
delete[]table;
}
int main()
{
func();
system("pause");
return0;
}