在一個字串裡面增加"."

[問題]
如果我要把
abcdefgh這個6個字的字串裡面增加「.」
例如
a.bcdefgh
ab.cdefgh
abc.defgh
.
.
.
a.b.cdefgh
a.bc.defgh
a.bcd.efgh
a.bcde.fgh
「.」的數量不限只要能把字串分開只要不要在字串前後加上都可以,最多到7個「.」,所有有可能產生的狀況都要列出來,要怎麼寫呢?

[解答]

這是 Boland C
+和\要改回半形字才能執行



#include
#include



main()
{
char dot[2][2];



int i1, i2, i3, i4, i5, i6, i7;



dot[0][0] = 0;
dot[1][0] = '.';



for (i1 = 0; i1 < 2; i1++)
for (i2 = 0; i2 < 2; i2++)
for (i3 = 0; i3 < 2; i3++)
for (i4 = 0; i4 < 2; i4++)
for (i5 = 0; i5 < 2; i5++)
for (i6 = 0; i6 < 2; i6++)
for (i7 = 0; i7 < 2; i7++)
printf("a%sb%sc%sd%se%sf%sg%sh\n",
dot[i1],dot[i2],dot[i3],dot[i4],dot[i5],dot[i6],dot[i7]);



return 0;
}

arrow
arrow
    全站熱搜

    deskwoodss 發表在 痞客邦 留言(0) 人氣()