演算法競賽入門經典(第2版)例題(第3章)

2021-10-10 22:34:11 字數 1613 閱讀 5954

例題 3-1 tex中的引號(tex quotes)

#include

intmain()

else

printf

("%c"

, c);}

return0;

}

例題 3-2 wertyu

#include

char s=

"`1234567890-=qwertyuiop\\asdfghjkl;'zxcvbnm,./"

;int

main()

}

例題 3-3 回文詞(palindromes)

#include

#include

#include

const

char

* rev =

"a 3 hil jm o 2tuvwxy51se z 8 "

;const

char

* msg=

;charr(

char ch)

intmain()

printf

("%s -- is %s.\n\n"

, s, msg[m*

2+p]);

}return0;

}

例題 3-4 猜數字遊戲的提示(master-mind hints)

#include

#define maxn 1010

intmain()

if(b[0]

==0)break

;for

(int d =

1; d <=

9; d++)if

(c1 < c2)

b += c1;

else

b += c2;

}printf

(" (%d,%d)\n"

, a, b-a);}

}return0;

}

例題 3-5 生成元(digit generator)

#include

#include

#define maxn 100005

int ans[maxn]

;int

main()

if(ans[y]==0

|| m < ans[y]

) ans[y]

= m;

}scanf

("%d"

,&t)

;while

(t--

)return0;

}

例題 3-6 環狀序列(circular sequence)

#include

#include

#define maxn 105

//環狀串s的表示法p是否比表示法q的字典序小

intless

(const

char

* s,

int p,

int q)

intmain()

}

演算法競賽入門經典 第2版 習題2 3詳解

畫圖分析 第二個迴圈 列印 for k 1 k 2 n i 1 k printf n 換行 return 0 執行結果 上面寫的是列印倒三角形的 到這裡我覺得還是有必要寫乙個列印正三角形的 列印 for k 1 k 2 i 1 k printf n 換行 return 0 執行結果 綜上所述 其實這...

演算法競賽入門經典第3章習題

給出乙個有o和x組成的串 長度為1 80 統計得分。每個o的得分為目前連續出現的o的個數,x的得分為0。例如,ooxxoxxooo的得分是為1 2 0 0 1 0 0 1 2 3。按照題目說的做就行了,超簡單。include include define maxn 80 char s maxn in...

演算法競賽入門經典例題

7744問題 問題 輸出所有形如aabb的四位完全平方數 即前兩位數字相等,後兩位數字也相等 include include int main 開燈問題 include include define maxn 1010 int a maxn int main int n,k,first 1 mems...