Questions in category: C++ (C++)
软件 >> C++
<[1] [2] [3] [4] >

1. C 语言中打开文件的代码

Posted by haifeng on 2023-03-05 11:27:43 last update 2023-03-05 11:42:17 | Answers (0) | 收藏


 

FILE* inputFile;

const char * file_in;

if ((inputFile = fopen(file_in, "r")) == NULL)     //读取输入文件
{
printf("\nerror: 无法打开输入文件: %s\n\n", file_in);
std::cerr << "Parser: could not open input file '" << file_in << "'!\n";
return EXIT_FAILURE;
}

 

但若在 Visual Studio 下, 会提示 fopen 不安全, 建议使用 fopen_s.

//Declaring a variable of type errno_t to store the return value of fopen_s
    errno_t error_code1; 
    //Opening file in r mode
    error_code1 = fopen_s(&inputFile, file_in, "r");
    if (error_code1 != 0) {
        printf("Error! Failed to open file %s in r mode!", file_in);
    }

3. 检测输入的参数 str 是否是有效的二进制表达式

Posted by haifeng on 2023-02-14 10:49:44 last update 2023-02-14 10:49:44 | Answers (0) | 收藏


//检测 str 是否只包含数字0或1, 也就是检测是否是二进制数
//11010010 

bool BigNumber::isBinaryNumber(const string &str)
{
    return find_if(str.begin(), str.end(),
        [](char c) { 
          return !((c=='0') || (c=='1')) ;
        }) == str.end();
}

 

修改上面的程序, 使满足下面的要求

1111011.01110100101111 也是有效的二进制数. 注意小数点最多只能一个.

4. 整数到字符串的转换

Posted by haifeng on 2022-06-25 12:06:58 last update 2022-06-25 12:53:00 | Answers (0) | 收藏


在非标准 C 库中有一个函数 itoa, 可以将各种进制的整数转换为C风格的字符串.

函数原型为

char *  itoa ( int value, char * str, int base );

 

字符串转为长整型

long int atol ( const char * str );

 

5. 程序设计竞赛网站

Posted by haifeng on 2022-03-30 11:40:45 last update 2022-03-30 11:40:45 | Answers (0) | 收藏


洛谷

https://www.luogu.com.cn/

 

蓝桥杯

https://dasai.lanqiao.cn/

 

ACM/ICPC 信息站
http://acmicpc.info

中国大学生程序设计竞赛
China Collegiate Programming Contest
https://ccpc.io/

6. Compiler Explorer

Posted by haifeng on 2022-03-09 12:31:49 last update 2022-03-09 12:31:49 | Answers (0) | 收藏


Compiler Explorer (godbolt.org)

https://godbolt.org/

 

C++  -->  汇编

7. 文件操作

Posted by haifeng on 2022-02-16 09:06:25 last update 2022-02-16 09:06:25 | Answers (0) | 收藏


现在有扫描后的若干文件, 命名如下.

 

    扫描.pdf
    扫描0001.pdf
    扫描0002.pdf
    扫描0003.pdf
    扫描0004.pdf
    扫描0005.pdf
    扫描0006.pdf
    扫描0007.pdf
    扫描0008.pdf
    ... ... ... ... ...
    扫描0143.pdf
    扫描0144.pdf
    扫描0145.pdf
    扫描0146.pdf
    扫描0147.pdf


但是其中文件名末尾数字凡是奇数的, 都需要进一步操作(旋转180°). 

请将这些文件 "扫描xxxx.pdf" 其中 xxxx 为奇数的移动(或拷贝)到一个文件夹.

 

可以使用任何语言, 例如:  Perl, PHP, Python, C, C++, 批处理等等.

8. 关于 $e$ 的连分数表达式

Posted by haifeng on 2022-02-06 15:48:45 last update 2022-02-06 15:50:33 | Answers (0) | 收藏


证明:

\[
e=3+\frac{-1}{4+\frac{-2}{5+\frac{-3}{6+\frac{-4}{7+\frac{-5}{8+\cdots}}}}}
\]

 

编写程序, 输入 N, 输出形如下面的表达式. 

例如: 当 N=9 时, 输出

3+(-1)/(4+(-2)/(5+(-3)/(6+(-4)/(7+(-5)/(8+(-6)/(9+(-7)/10))))))

即 $3+(-1)/(4+(-2)/(5+(-3)/(6+(-4)/(7+(-5)/(8+(-6)/(9+(-7)/10))))))$

9. .pdb 文件是什么?

Posted by haifeng on 2021-12-08 11:08:35 last update 2021-12-08 11:10:11 | Answers (0) | 收藏


.pdb 是程序数据库文件.    program database

 

 

参考

调试之pdb文件(C++)_HITXuQin的专栏-CSDN博客_c++ pdb 调试

10. 快速幂运算

Posted by haifeng on 2021-06-22 11:56:24 last update 2021-06-22 11:56:24 | Answers (0) | 收藏


快速幂运算

 

 

References:

Fast Power Algorithm - Exponentiation by Squaring - C++ and Python Implementation | Rookie's Lab (rookieslab.com)

 

<[1] [2] [3] [4] >