題目:
(The C Programming Language)
移除C code裡的comments。
解法:
分別處理(1) escape sequence (2) one line comments (3) multiline comments即可。
卡在對&&觀念不熟,囧,邏輯課重修……
20101030
20101029
[C] Ex1-20
The C Programming Language
題目:
Write a program detab that replaces tabs in the input with the proper number of blanks to space to the next tab stop. Assume a fixed set of tab stops, say every n columns. Should n be a variable or a symbolic parameter?
解法:
一開始看不懂題目在寫甚麼……原來只是要我們用C模擬tab的作用方式。
找到tab stop的規則即可輕鬆解決。
tab stop會出現在n + 1的位置。(假設ts = n)
題目:
Write a program detab that replaces tabs in the input with the proper number of blanks to space to the next tab stop. Assume a fixed set of tab stops, say every n columns. Should n be a variable or a symbolic parameter?
解法:
一開始看不懂題目在寫甚麼……原來只是要我們用C模擬tab的作用方式。
找到tab stop的規則即可輕鬆解決。
tab stop會出現在n + 1的位置。(假設ts = n)
[C_Programming]Ex1-16
題目:
Revise the main routine of the longest-line program so it will correctly print the length of arbitrarily long input lines, and as much as possible of the text.
解法:
一直卡在當overflow時,i會自動再run一次getline(),我不知道為什麼,所以無法直接測出該行字串的長度(如果溢位的話)。於是用另一個j來測量長度,i只做getline的動作。
Revise the main routine of the longest-line program so it will correctly print the length of arbitrarily long input lines, and as much as possible of the text.
解法:
一直卡在當overflow時,i會自動再run一次getline(),我不知道為什麼,所以無法直接測出該行字串的長度(如果溢位的話)。於是用另一個j來測量長度,i只做getline的動作。
The C Programming Language
這本書算是C的聖經書,言簡意賅,想了解C,讀這本書就對了。
把一些比較奇怪,或是說讓我覺得很Orz的題目po上來,供大家參考。
2011/09/13 update: code不會特別附上,避免有人copy……話說我寫這麼爛應該也沒人要copy lol。
2011/10/12 update: 後來想想code放上來也沒差,反正網路有一堆人寫的code。
把一些比較奇怪,或是說讓我覺得很Orz的題目po上來,供大家參考。
2011/09/13 update: code不會特別附上,避免有人copy……話說我寫這麼爛應該也沒人要copy lol。
2011/10/12 update: 後來想想code放上來也沒差,反正網路有一堆人寫的code。
訂閱:
文章 (Atom)