c tips 待续、、、

来源:互联网 发布:msdn win7 优化 编辑:程序博客网 时间:2024/06/14 07:14

1.十六进制形式的输出:

    printf("%#x",i);    // 加上#有0x的显示。

2.c语言里面的long long

   OJ通常使用g++编译器,其64位扩展方式与VC有所不同,它们分别叫做 long long and unsigned long long,处理规模与输入输出相同,扩展比VC好,可以直接使用long long a;定义一个64位的整形,也可使用 scanf("%lld",&a);
printf("%lld",a);

vc 里面用_int64 来定义。

3.c语言动态分配数组长度,读入数据

     long *P,*A; 

    P = (long *)malloc(N*sizeof(long)); // P is the price
    A = (long *)malloc(N*sizeof(long)); // A is the amount

    for(i = 0; i < N; i++)
    {
        scanf("%ld %ld",P+i,A+i);
        printf("%ld,%ld\n",P[i],A[i]);

    }

4.随机数生成时加上随机种子

srand((unsigned)time(0));

5. printf("%p",q); 为打印地址。

6. The C formatting directive "%.2x" indicates that an integer should be printed in hexadecimal with at least two digits.


原创粉丝点击