在Leetcode刷题的时候,有时候会想在本地调试来定位错误,但是在本地生成测试用例非常麻烦,特别是对于一些大型二维数组的时候,于是我根据Leetcode二维数组的输入输入格式,写了一个自动生成int整型二维数组的函数,仅供参考。
使用方法:1、必须修改本地文档路径,格式为 “C:\Users\Administrator\Desktop\tmp.txt”
2、在路径指向位置生成一个名为 tmp.txt 的文档
3、在文档中粘贴格式为[[1,2,-3],[-4,5,6],[7,8,9]]的二维数组,保存后运行即可读取(如果只有一维,格式可简化为[1,2,-3])
使用模板如下:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#define bool int
#define true 1
#define false 0
#define pr(x) printf("value of "#x" is: %d\n",x)
#define ps(x) printf("value is: %s\n",x)
#define filepath "C:\\Users\\Administrator\\Desktop\\tmp.txt" //文档路径
#define CHARLEN 4096
#define NUMSLEN 1024 //表示二维数组大小,初始为1024*1024
bool isnum(char c){
return c>='0'&&c<='9'||c=='-'||c=='+';
}
//读取tmp.txt里二维数组,格式为[[1,2,-3],[-4,5,6],[7,8,9]]
void