c/c++ÓïÑÔÎÊÌâÖпɱä²ÎÊý
va_listÊÇc/c++ÓïÑÔÎÊÌâÖнâ¾ö¿É±ä²ÎÊýµÄÒ»×éºê.ÏÈÀ´¿´Ò»¸ö³ÌÐòÀý×Ó°É.
view plaincopy to clipboardprint?
#include <stdarg.h>
/**¡¡º¯ÊýÃû£ºmax
*¡¡¹¦ÄÜ£º·µ»Øn¸öÕûÊýÖеÄ×î´óÖµ
* ²ÎÊý£ºnum£ºÕûÊýµÄ¸öÊý ...£ºnum¸öÊäÈëµÄÕûÊý
* ·µ»ØÖµ£ºÇóµÃµÄ×î´óÕûÊý
*/
int max ( int num, ... )
{
¡¡int m = -0x7FFFFFFF; /* 32ϵͳÖÐ×îСµÄÕûÊý */
¡¡va_list ap;
¡¡va_start ( ap, num );
¡¡for ( int i= 0; i< num; i++ )
¡¡{
¡¡¡¡int t = va_arg (ap, int);
¡¡¡¡if ( t > m )
¡¡¡¡{
¡¡¡¡¡¡m = t;
¡¡¡¡}
¡¡}
¡¡va_end (ap);
¡¡return m;
}
/* Ö÷º¯Êýµ÷ÓÃmax */
int main ( int argc, char* argv[] )
{
¡¡int n = max ( 5, 5, 6 ,3 ,8 ,5); /* Çó5¸öÕûÊýÖеÄ×î´óÖµ */
¡¡cout << n;
¡¡return 0;
}
CÓïÑÔÖÐÓÐЩº¯ÊýʹÓÿɱä²ÎÊý£¬±ÈÈç³£¼ûµÄint printf( const char* format, ...)£¬µÚÒ»¸ö²ÎÊýformatÊǹ̶¨µÄ£¬ÆäÓàµÄ²ÎÊýµÄ¸öÊýºÍÀàÐͶ¼²»¹Ì¶¨.
CÓïÑÔÓÃva_startµÈºêÀ´´¦ÀíÕâЩ¿É±ä²ÎÊý¡£ÕâЩºê¿´ÆðÀ´ºÜ¸´ÔÓ£¬ÆäʵÔÀíͦ¼òµ¥£¬¾ÍÊǸù¾Ý²ÎÊýÈëÕ»µÄÌصã´Ó×î¿¿½üµÚÒ»¸ö¿É±ä²ÎÊýµÄ¹Ì¶¨²ÎÊý¿ªÊ¼£¬ÒÀ´Î»ñȡÿ¸ö¿É±ä²ÎÊýµÄµØÖ·¡£ÏÂÃæÎÒÃÇÀ´·ÖÎöÕâЩºê¡£
ÔÚstdarg.hÍ·ÎļþÖУ¬Õë¶Ô²»Í¬Æ½Ì¨Óв»Í¬µÄºê¶¨Ò壬ÎÒÃÇÑ¡
Ïà¹ØÎĵµ£º
ÎÊ:
È·ÈÏÒ»ÏÂc++Öв»ÄÜʹÓÃinterface£¨Èçjava£©ÄÇÑùµÄ¹¦ÄÜ°Ñ
ÎÒÈÏΪÊDz»Äܵģ¬×¢ÒâÎÒ˵µÄÊÇinterface£¨ÓÃÓÚjava¶àÖؼ̳еÄÄǸö£¬²»ÊÇÒ»°ãÒâÒåµÄ½Ó¿Ú£©
ÎÒ¾õµÃÊÇûÓеģ¬µ«ÊÇÍøÉÏËÑË÷˵ʲôµÄ¶¼ÓжøÇÒÈË»¹²»ÉÙ…… ËùÒÔÏ£Íû´ó¼ÒÄܸøÎÒÒ»¸öÃ÷È·µÄ´ð¸´ºÃô£¿×îºÃÄÜ»¹ÓÐһР......
½ñÌì¿´µ½Ò»ÖֱȽϰ²È«µÄö¾Ùд·¨£¡
enum example
{
item1 = 0,
item2,
item3,
item4,
item5,
max /* when you want to add element,please add before this */
};
µ±ÄãʹÓÃËüµÄʱºò£º
example ex1;
i ......
[
ÕªÒª]
Ö¸ÕëÊÇ
CºÍ
C++ÓïÑÔ±à³ÌÖÐ×îÖØÒªµÄ¸ÅÄîÖ®Ò»£¬Ò²ÊÇ×îÈÝÒײúÉúÀ§»ó²¢µ¼Ö³ÌÐò³ö´íµÄÎÊÌâÖ®Ò»¡£ÀûÓÃÖ¸Õë±à³Ì¿ÉÒÔ±íʾ¸÷ÖÖÊý¾Ý½á¹¹
, ͨ¹ýÖ¸Õë¿ÉʹÓÃÖ÷µ÷º¯ÊýºÍ±»µ÷º¯ÊýÖ®¼ä¹²Ïí±äÁ¿»òÊý¾Ý½á¹¹£¬±ãÓÚʵÏÖË«ÏòÊý¾ÝͨѶ£»²¢ÄÜÏñ»ã±àÓïÑÔÒ»Ñù´¦ÀíÄÚ´æµØÖ·£¬´Ó¶ø±à³ö¾«Á·¶ø¸ßЧµÄ³ÌÐò¡£Ö¸Õ뼫´óµØ·á¸»ÁË ......
UVa Online Judge - Volume C ÌâÄ¿ºÍ½â´ðË÷Òý¡£Ç°ÃæΪÔÌâÁ´½Ó£¬ºóÃæΪÎҵĽâ´ðÁ´½Ó¡£
·µ»Ø×ÜĿ¼
10003 - Cutting Sticks
Dynamic Programming
Solution
10004 - Bicoloring
Graph: BFS
Solution
10006 - Carmichael Numbers
Number Theory: Modulus
Solution
10010 - Where's Waldorf?
String
Solution ......