]]>Printing ONE TWO THREE http://www.shnenglu.com/kenwell/archive/2008/10/11/63760.htmlc++ 瀛︿範(fàn)c++ 瀛︿範(fàn)Sat, 11 Oct 2008 11:51:00 GMThttp://www.shnenglu.com/kenwell/archive/2008/10/11/63760.htmlhttp://www.shnenglu.com/kenwell/comments/63760.htmlhttp://www.shnenglu.com/kenwell/archive/2008/10/11/63760.html#Feedback0http://www.shnenglu.com/kenwell/comments/commentRss/63760.htmlhttp://www.shnenglu.com/kenwell/services/trackbacks/63760.html- You're given the following program: -------------------------------- int main() { printf("TWO\n"); return 0; } ---------------------------------
Add any code above or below the lines so that the output is
ONE TWO THREE Give 10 different ways to do this and which of them are specific to C++?
: just comment it out (already mentioned) #include <iostream> int main() { std::cout << "ONE\nTWO\nTHREE\n"; return 0; } /* ... */
2: use #if or #ifdef #include <iostream> #ifdef foo ... #else int main() { std::cout << "ONE\nTWO\nTHREE\n"; return 0; } #endif
6: redefine main #include <iostream> int foo(); int main() {std::cout << "ONE\n"; foo(); std::cout << "THREE\n"; return 0; } #define main foo ...
7: put main in a namespace (c++ specific) #include <iostream> namespace foo { ... }; int main() { std::cout << "ONE\n"; foo::main(); std::cout << "THREE\n"; return 0; }
8: put main in a class or struct (c++ specific) #include <iostream> struct foo { ... }; int main() { foo bar; std::cout << "ONE\n"; bar.main(); std::cout << "THREE\n"; return 0; }
9: use #define to remove keywords #include <iostream> int main() { printf("ONE\n"); #define main() do #define return #define int ... while (!printf("THREE\n")); #undef return return 0; }
10: abuse a class or struct constructor (c++ specific) struct printf { printf(const char * s); }; ... #include <iostream> printf::printf(const char * s) { std::cout << "ONE\n" << s << "THREE\n"; }
]]>c++緇忓吀涔︾睄鎺ㄨ崘鍜屼笅杞?/title>http://www.shnenglu.com/kenwell/archive/2007/10/24/35065.htmlc++ 瀛︿範(fàn)c++ 瀛︿範(fàn)Wed, 24 Oct 2007 08:45:00 GMThttp://www.shnenglu.com/kenwell/archive/2007/10/24/35065.htmlhttp://www.shnenglu.com/kenwell/comments/35065.htmlhttp://www.shnenglu.com/kenwell/archive/2007/10/24/35065.html#Feedback7http://www.shnenglu.com/kenwell/comments/commentRss/35065.htmlhttp://www.shnenglu.com/kenwell/services/trackbacks/35065.html娣卞害鎺㈢儲(chǔ)C++瀵硅薄妯″瀷 鑻辨枃鐗?http://www.nengxia.com/soft.asp?id=5 涓枃鐗堬細(xì)http://www.nengxia.com/soft.asp?id=19
Modern C++ Design http://www.nengxia.com/soft.asp?id=7
c++緙栫▼鎬濇兂 絎竴鍗鳳細(xì) 涓枃鐗?http://www.nengxia.com/soft.asp?id=1039 鑻辨枃鐗堬細(xì) Prentice Hall Bruce Eckel Thinking In C++, Second EditionVolume.1 絎簩鍗鳳細(xì) 涓枃鐗堬細(xì)http://www.nengxia.com/soft.asp?id=1040 鑻辨枃鐗堬細(xì)http://www.nengxia.com/soft.asp?id=1041
c++ Programming language 涓枃鐗堬細(xì)http://www.nengxia.com/soft.asp?id=1038 鑻辨枃鐗堬細(xì)http://www.nengxia.com/soft.asp?id=368
C++ Primer 絎笁鐗堜腑鏂囩増錛歨ttp://www.nengxia.com/soft.asp?id=6 絎洓鐗?br>鑻辨枃鐗堬細(xì)http://www.nengxia.com/soft.asp?id=117 涓枃鐗堬細(xì)http://www.nengxia.com/soft.asp?id=635 c++ primer 棰樿В http://www.nengxia.com/soft.asp?id=17
C++ Primer plus 絎?鐗堜腑鏂囷細(xì) 涓枃鐗堬細(xì)http://www.nengxia.com/soft.asp?id=987 鑻辨枃鐗堬細(xì) Third.Editionhttp://www.nengxia.com/soft.asp?id=1037 Special.Edition錛歨ttp://www.nengxia.com/soft.asp?id=369
Effective C++ 涓枃鐗堬細(xì)http://www.nengxia.com/soft.asp?id=9 鑻辨枃鐗堬細(xì)http://www.nengxia.com/soft.asp?id=1033
More Effective C++ 涓枃鐗堬細(xì)http://www.nengxia.com/soft.asp?id=8
STL婧愮爜鍓栨瀽 http://www.nengxia.com/soft.asp?id=11
c++ template 鑻辨枃鐗堬細(xì) http://www.nengxia.com/soft.asp?id=1034 綆浣撲腑鏂囩増錛?br>http://www.nengxia.com/soft.asp?id=15 綣佷綋涓枃鐗堬細(xì) http://www.nengxia.com/soft.asp?id=16
Problem A.Fibonacci Input:聽聽聽聽聽聽聽聽聽 聽fib.in Output:聽聽聽聽聽聽聽 Standard Output Time limit:聽聽聽 聽5 second Memory limit: 64 megabytes Offerd by 錛毬犅?http://spaces.msn.com/davidblogs/
聽
The Fibonacci Numbers{0,1,1,2,3,5,8,13,21,34,55...} are defined by the recurrence: F0=0 F1=1 Fn=Fn-1+Fn-2,n>=2 Write a program to calculate the Fibonacci Numbers.
聽
Input The input file contains a number n and you are expected to calculate Fn.(0<=n<=30)
Output Print a number Fn on a separate line,which means the nth Fibonacci Number.
聽
Example fib.in聽聽聽聽聽聽 Standard Output 1聽聽聽聽聽聽聽聽聽聽聽 1 2聽聽聽聽聽聽聽聽聽聽聽 1 3聽聽聽聽聽聽聽聽聽聽聽 2 4聽聽聽聽聽聽聽聽聽聽聽 3 5聽聽聽聽聽聽聽聽聽聽聽 5 6聽聽聽聽聽聽聽聽聽聽聽 8
聽
Problem B.WERTYU Input:聽聽聽聽聽聽聽聽聽 聽wertyu.in Output:聽聽聽聽聽聽 聽 Standard Output Time limit:聽聽聽聽 聽5 second Memory limit:聽 64 megabytes Offerd by 錛毬犅?http://spaces.msn.com/davidblogs/
聽
A common typing error is to place the hands on the keyboard one
row to the right of the correct position.So "Q" is typed as "W" and "J"
is typed as "K" and so on.You are to decode a message typed in this
manner.
聽
` 1 2 3 4 5 6 7 8 9 0 - = BackSp Tab Q W E R T Y U I O P [ ] \ A S D F G H J K L ; ' Enter Z聽 X聽 C聽 V聽 B聽 N聽 M聽 ,聽 .聽 / Control Alt聽 Space聽 Alt Control
聽
Input The input file consist of several lines of text.Each line
may contain digits,spaces,upper case letters(except Q,A,Z),or
punctuation shown above(except back-quote(') which is left to the key
"1").Keys labelled with words [Tab,BackSp,Control,etc.] are not
represented in the input.
聽
Output You are to replace each letter or punctuation symbol by
the one immediately to its left on the QWERTY keyboard shown
above.Spaces in the input should be echoed in the output.
聽
Example wertyu.in聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽Standard Output O S, GOMR YPFSU/聽聽聽聽聽聽聽 I AM FINE TODAY.
聽
聽
Problem C.String Matching Input:聽聽聽聽聽聽聽聽聽 聽聽matching.in Output:聽聽聽聽聽聽 聽 Standard Output Time limit:聽聽聽聽 聽5 second Memory limit:聽 64 megabytes Offerd by 錛毬犅?http://spaces.msn.com/davidblogs/
聽
Finding all occurrences of a pattern in a text is a problem that
arises frequently in text-editing programs.Typically,the text is a
document being edited,and the pattern searched for is a particular word
supplied by the user.
聽
We assume that the text is an array T[1..n] of length n and that
the pattern is an array P[1..m] of length m<=n.We further assume
that the elements of P and T are all alphabets(鈭?{a,b...,z}).The
character arrays P and T are often called strings of characters.
聽
We say that pattern P occurs with shift s in the text T if
0<=s<=n and T[s+1..s+m] = P[1..m](that is if T[s+j]=P[j],for
1<=j<=m).
聽
If P occurs with shift s in T,then we call s a valid shift;otherwise,we call s a invalid shift.
Your task is to calculate the number of vald shifts for the given text T and pattern P.
聽
Input In the input file,there are two strings T and P on a
line,separated by a single space.You may assume both the length of T
and P will not exceed 10^6.
聽
Output You should output a number on a separate line,which indicates the number of valid shifts for the given text T and pattern P.
Problem D.Exponential Form Input:聽聽聽聽聽聽聽聽聽 聽 form.in Output:聽聽聽聽聽聽聽聽聽Standard Output Time limit:聽聽聽聽聽 5 second Memory limit:聽 64 megabytes Offerd by 錛毬犅?http://spaces.msn.com/davidblogs/
聽
Every positive number can be presented by the exponential form.For example, 137 = 2^7 + 2^3 + 2^0
Let's present a^b by the form a(b).Then 137 is presented by 2(7)+2(3)+2(0). Since 7 = 2^2 + 2 + 2^0 and 3 = 2 + 2^0 , 137 is finally presented by 2(2(2)+2+2(0))+2(2+2(0))+2(0).
聽
Given a positive number n,your task is to present n with the exponential form which only contains the digits 0 and 2.
聽
Input The input file contains a positive integer n (n<=20000).
聽
Output You should output the exponential form of n an a single
line.Note that,there should not be any additional white spaces in the
line.
]]>鍑芥暟涓湁鏈煡涓弬鏁扮殑瀹氫箟http://www.shnenglu.com/kenwell/archive/2006/03/21/4407.htmlc++ 瀛︿範(fàn)c++ 瀛︿範(fàn)Tue, 21 Mar 2006 04:39:00 GMThttp://www.shnenglu.com/kenwell/archive/2006/03/21/4407.htmlhttp://www.shnenglu.com/kenwell/comments/4407.htmlhttp://www.shnenglu.com/kenwell/archive/2006/03/21/4407.html#Feedback0http://www.shnenglu.com/kenwell/comments/commentRss/4407.htmlhttp://www.shnenglu.com/kenwell/services/trackbacks/4407.htmlva_arg, va_start, va_end va_arg: typeva_arg( 聽聽 va_listarg_ptr, 聽聽 type );
va_arg returns the current argument; va_start and va_end do not return values
The va_arg, va_end, and va_start macros provide a portable way to access the arguments to a function when the function takes a variable number of arguments. Two versions of the macros are available: The macros defined in STDARG.H conform to the ANSI C standard, and the macros defined in VARARGS.H are compatible with the UNIX System V definition. The macros are:
The ANSI C standard macros, defined in STDARG.H, are used as follows:
All required arguments to the function are declared as parameters in the usual way. va_dcl is not used with the STDARG.H macros.
va_start sets arg_ptr to the first optional argument in the list of arguments passed to the function. The argument arg_ptr must have va_list type. The argument prev_param is the name of the required parameter immediately preceding the first optional argument in the argument list. If prev_param is declared with the register storage class, the macro's behavior is undefined. va_start must be used before va_arg is used for the first time.
va_arg retrieves a value of type from the location given by arg_ptr and increments arg_ptr to point to the next argument in the list, using the size of type to determine where the next argument starts. va_arg can be used any number of times within the function to retrieve arguments from the list.