]]>sscanfhttp://www.shnenglu.com/liyuxia713/archive/2010/04/25/113530.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Sun, 25 Apr 2010 12:13:00 GMThttp://www.shnenglu.com/liyuxia713/archive/2010/04/25/113530.htmlhttp://www.shnenglu.com/liyuxia713/comments/113530.htmlhttp://www.shnenglu.com/liyuxia713/archive/2010/04/25/113530.html#Feedback0http://www.shnenglu.com/liyuxia713/comments/commentRss/113530.htmlhttp://www.shnenglu.com/liyuxia713/services/trackbacks/113530.htmlint sscanf(const char* str, const char* format, ...) functions: Reads data from str and stores them according to the parameter format into the locations given by the additional arguments. Locations pointed by each additional argument are filled with their corresponding type of value specified in the format string.
In the format: Whitespace character: the function will read and ignore any whitespace characters which are encounterd before the next non-whitespace character. Non-whitespace character: except percentage signs(%): any character that is not either a whitespace character or part of a format specifier causes the function to read the next character from str, compare it to this non-whitespace character and if it matches, it is discarded and the function continues with the next character of format and str. If the character does not match, the function fails and returns. Return Value: On success. the function returns the number of items successfully read. On failure: In the case of an input failure before any data could be successfully read, EOF is returnded.
Portotype: int printf(char* str, const char* format, parameters);
Writes into the array pointed by str a C string consisting on a sequence of data formatted as the format argument specifies. After the format parameter, the function expects at least as many additional arguments as specified in format.
This function behaves exactly as printf does, but writing its result to a string instead of stdout. The size of the array passed as str should be enough to contain the entire formatted string .
Return value:
On success, the total number of characters written is returned. This count does not include the additional null-character automatically appended at the end of the string.
//Success //The size of str is long enough //the number of additional number match with the format constint size =25; char*str =newchar[size]; //same as int flag1 = sprintf(str,"%s is written to str.","Test","tEST"); int flag1 = sprintf(str,"%s is written to str.","Test"); //Console: 23-Test is written to str cout << flag1 <<"-"<< str << endl;
On failure, a negative number is returned.
//Failure1 //additional arguments numbers is less than specified is format //the second %s transmited as unrecognizable words constint size =25; char*str =newchar[size]; int flag2 = sprintf(str,"%s %s tttttttttttt","Test"); //Console: 19--Test @ tttttttttttt cout << flag2 <<"--"<< str << endl;
//Failure2:the size of str is not long enough // 鍦╠ev c++涓嶈兘榪愯錛寁c6.0娌掓湁闂 constint size =25; char*str =newchar[size]; int flag3 = sprintf(str,"%s jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj","Test"); //VC6.0 Console: Test jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj //Dev c++: Console: the same as vc6.0 but throws an cannot read memory exception cout << flag3 <<"--"<< str << endl;
]]>Order Statistics 欏哄簭緇熻錛堟壘鍑虹i灝忓厓绱狅級http://www.shnenglu.com/liyuxia713/archive/2010/01/21/106151.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Thu, 21 Jan 2010 08:29:00 GMThttp://www.shnenglu.com/liyuxia713/archive/2010/01/21/106151.htmlhttp://www.shnenglu.com/liyuxia713/comments/106151.htmlhttp://www.shnenglu.com/liyuxia713/archive/2010/01/21/106151.html#Feedback0http://www.shnenglu.com/liyuxia713/comments/commentRss/106151.htmlhttp://www.shnenglu.com/liyuxia713/services/trackbacks/106151.htmlOrder Statistics 欏哄簭緇熻
Select(int* a, int n, int ith): 浠庣粰瀹氱殑n涓厓绱犱腑鎵懼嚭絎琲涓皬鐨勫厓绱? 鎬濇兂錛歈uickSort鐨凱artition鏂規(guī)硶榪涜鍒嗗壊
濡傛灉 i = rank(pivot), 鍒欒繑鍥瀉[k]
濡傛灉 i < rank(pivot), 鍒欎粠鍓嶅崐閮ㄥ垎涓壘絎琲涓皬鐨勫厓绱? 濡傛灉 i > rank(pivot), 鍒欎粠鍚庡崐閮ㄥ垎涓壘絎琲-rank(pivot)涓皬鐨勫厓绱?
鏈鍧忚繍琛屾椂闂碠(n^2)
騫沖潎榪愯鏃墮棿O(nlgn) 闃呰鍏ㄦ枃