2、char *gets(char *str)
str -- This is the pointer to an array of chars where the C string is stored.
This function returns str on success, and NULL on error or when end of file occurs while no characters have been read. Null is defined 0
测试用例无限输入,每个测试用例占用一行
char str[N] ;
while(gets(str))
{
int n = strlen(str) ;
if(0==n) //空行跳过
{
printf("\n") ;
continue ;
}
}
#include <string.h>
Sets the first num bytes of the block of memory pointed by ptr to the specified value
4、测试用例以0结束
double d ;
while(1==scanf("%lf",&d)&&d)
{
}
或者
while (true)
{
double d ;
scanf("%lf",&d) ;
if(d==0.0) break ;
}
5、printf格式字符串
- long long定义方式可以用于gcc/g++,不受平台限制,但不能用于VC6.0。
- __int64是Win32平台编译器64位长整型的定义方式,不能用于Linux。
- "%lld"用于Linux i386平台编译器,"%I64d"用于Win32平台编译器。
- cout只能用于C++编译,在VC6.0中,cout不支持64位长整型
- long long一般是Linux下申明方式,_int64一般是Windows下使用64位的申明方式
long long a[n] ;
double d ;
printf(“%6.2lf%17I64d\n”,d,a[n]) //d小数部分两位,向右对齐,宽度为6,数组也向右对齐,宽度为17
向左对齐,右边填空格,只需要加-
printf("%-6.2lf\n",5.2) ;
向右对齐,左边以前导0填充,只需要加0
printf("%06.2lf\n",5.2) ;