写一个程序,打印出以下的序列。
(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),(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)
- const char arr[]="a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";
- char tmp[sizeof(arr)];
- for(int i = 0; i < 26; i++)
- {
- memset(tmp,0,sizeof(arr));
- strncpy(tmp,arr,i*2+1);
- for(;;)
- {
- for(;tmp[i*2]<'z';)
- {
- printf("(%s),",tmp);
- tmp[i*2]++;
- }
- printf("(%s)",tmp); // 最后一个,不需要逗号
- //printf("\n");
- if(0 == strncmp(tmp,arr+25*2-i*2,i*2+1))
- break;
- int j = 0;
- for(;j <= i;j++)
- {
- if(tmp[j*2] == arr[25*2-i*2+j*2])
- break;
- }
- tmp[(j-1)*2]++;
- for(;j<=i;j++)
- {
- tmp[j*2] = tmp[(j-1)*2]+1;
- }
- }
- printf("\n");
- }