当前位置: 首页 > news >正文

美肤宝网站建设网络推广工作内容

美肤宝网站建设,网络推广工作内容,wordpress 邮箱 通知,南京移动网站设计HJ41 称砝码 提示#xff1a;文章 文章目录 前言一、背景二、 2.1 2.2 总结 前言 前期疑问#xff1a; 本文目标#xff1a; 一、背景 这个题目之前是没有做出来的#xff0c;我把之前没做出来的代码也记录一下 二、 2.1 之前的代码 #include stdio.hint m…HJ41 称砝码 提示文章 文章目录 前言一、背景二、 2.1 2.2 总结 前言 前期疑问 本文目标 一、背景 这个题目之前是没有做出来的我把之前没做出来的代码也记录一下 二、 2.1 之前的代码 #include stdio.hint main() {int a, b;int num 0;int array[20000] {0};while (scanf(%d, num) ! EOF) { // 注意 while 处理多个 case// 64 位输出请用 printf(%lld) to int key[num];int value[num];int count 0;for(int i 0; i num; i){scanf(%d, key[i]);}for(int i 0; i num; i){scanf(%d, value[i]);}for(int i 0; i num; i){while(value[i]){int heigh key[i] * value[i];array[heigh] 1;value[i]--;}}for(int i 0; i 20000; i){if(array[i] 0){count;}}printf(%d\n, count 1);printf(%d , 0);for(int i 0; i 20000; i){if(array[i] 0){printf(%d , i);}}}return 0; }示例是没有通过的 自测输入21 22 1预期输出5实际输出30 1 2 2.2 今天编的代码 2024年6月20日12:28:44 #include stdio.h #include stdlib.h #include string.hint compare(const void* a, const void* b) {return (int*)a - (int*)b; }int main() {int count 0;char countStr[3] {\0};while (fgets(countStr, 3, stdin) ! NULL) { // 注意 while 处理多个 case// 64 位输出请用 printf(%lld) to countStr[1] \0;count atoi(countStr[0]);int weight[count];memset(weight, 0, sizeof(weight));int num[count];memset(num, 0, sizeof(num));char weightStr[21];char numStr[21];int weightIndex 0;int numIndex 0;fgets(weightStr, 21, stdin);fgets(numStr, 21, stdin);int len strlen(weightStr);weightStr[strlen(weightStr) - 1] \0;numStr[strlen(numStr) - 1] \0;char* p strtok(weightStr, );while(p){weight[weightIndex] atoi(p);p strtok(NULL, );}p strtok(numStr, );while(p){num[numIndex] atoi(p);p strtok(NULL, );}for(int i 0; i count; i){//printf(weight:%d, num:%d\n, weight[i], num[i]);}int length pow(count, 2);int resultArray[length 3];memset(resultArray, 0, sizeof(int) * (length 3));//int resultArrayIndex 1; //把0算作一个重量,把单独的重量也算上int resultArrayIndex 0; //把0算作一个重量,把单独的重量也算上for(int i 0; i count; i){for(int j 0; j num[i]; j){resultArray[resultArrayIndex] weight[i] * j; }}for(int i 0; i count; i){for(int j 0; j count; j){resultArray[resultArrayIndex] weight[i] num[j];}}int tempArray[20001] {0};for(int i 0; i resultArrayIndex; i){tempArray[resultArray[i]];}int resultArrayCopy[length 3];int resultArrayCopyIndex 0;for(int i 0; i 20001; i){if(tempArray[i] ! 0){// printf(index:%d, %d\n, i, tempArray[i]);resultArrayCopy[resultArrayCopyIndex] i;}}printf(%d, resultArrayCopyIndex);}return 0; }示例有误 用例输入274 1853 1预期输出8实际输出7 2.3 2024年7月5日10:55:33编写代码 2024年7月5日10:55:33 现在的问题就是卡在测试用例18/20问题是 请检查是否存在数组、列表等越界非法访问内存非法访问等情况。 这个问题待解决。 这次我调试代码的时候将测试用例用googleTest创建了单元测试下面是CLion上的测试用例代码 Clion调试代码如下 #include HJ41.h//#define TEST_DEBUG #define TEST_DEBUG_ARRAY_PRINTint calculateWeight(int *weight, int weightLen, int *num, int numLen) {int array[20001] {0};int hash[300001] {0};hash[0] 1;int arrayIndex 1;for(int i 1; i num[0]; i){int tempWeight weight[0] * i;if(hash[tempWeight] 0){array[i] tempWeight;arrayIndex;}hash[array[i]];}for(int i 1; i numLen; i){int tempArrayIndex arrayIndex;for(int j 1; j num[i]; j){for(int k 0; k tempArrayIndex; k){int tempWeight j * weight[i] array[k];if(tempWeight 300000 hash[tempWeight] 0){hash[tempWeight];array[arrayIndex] tempWeight;arrayIndex;}}}}#ifdef TEST_DEBUG_ARRAY_PRINTfor(int i 0; i arrayIndex; i){printf(array[%d]:%d , i, array[i]);}#endifreturn arrayIndex; }int calculateWeight2(int *weight, int weightLen, int *num, int numLen) {int array[2000] {0};int hash[2000] {0};hash[0] 1;int arrayIndex 1;for(int i 1; i num[0]; i){int tempWeight weight[0] * i;if(hash[tempWeight] 0){array[i] tempWeight;arrayIndex;}hash[array[i]];}for(int i 1; i numLen; i){int tempArrayIndex arrayIndex;for(int j 1; j num[i]; j){for(int k 0; k tempArrayIndex; k){int tempWeight j * weight[i] array[k];if(tempWeight 2000 hash[tempWeight] 0){hash[tempWeight];array[arrayIndex] tempWeight;arrayIndex;} #ifdef TEST_DEBUGstd::cout j: j std::endl;std::cout tempWeight: tempWeight std::endl; #endif}}} #ifdef TEST_DEBUG_ARRAY_PRINTfor(int i 0; i arrayIndex; i){std::cout array[ i ] array[i] ;} #endifreturn arrayIndex; }写的测试用例如下 #include gtest/gtest.h // googletest header file #include iostream #include HJ41.hclass googleMyTest : public testing::Test { public:static void SetUpTestCase(){std::cout SetUpTestCase std::endl;}static void TearDownTestCase(){std::cout TearDownTestCase std::endl;}virtual void SetUp(){std::cout SetUp std::endl;}virtual void TearDown(){std::cout TearDown std::endl;} };TEST_F(googleMyTest, my_test_f_1) {int x 1;EXPECT_EQ(x, 1); }TEST_F(googleMyTest, HJ41_1) {int count 2;int weight[2] {1, 2};int num[2] {2, 1};int totalCount calculateWeight(weight, count, num, count);EXPECT_EQ(totalCount, 5); }TEST_F(googleMyTest, HJ41_2) {int count 2;int weight[2] {74, 185};int num[2] {3, 1};int totalCount calculateWeight(weight, count, num, count);EXPECT_EQ(totalCount, 8); }TEST_F(googleMyTest, HJ41_3) {int count 3;int weight[] {108, 29, 185};int num[] {5, 2, 1};int totalCount calculateWeight(weight, count, num, count);EXPECT_EQ(totalCount, 36); }/** 这一版之前一直过不了是因为少了这个语句* hash[tempWeight];*/ TEST_F(googleMyTest, HJ41_4) {int count 3;int weight[] {10, 191, 103};int num[] {6, 6, 5};int totalCount calculateWeight(weight, count, num, count);EXPECT_EQ(totalCount, 254); }/** 报错段错误*/ //7 //172 162 18 153 199 41 28 //1 1 3 5 1 4 1 TEST_F(googleMyTest, HJ41_5) {int count 7;int weight[] {172, 162, 18, 153, 199, 41, 28};int num[] {1, 1, 3, 5, 1, 4, 1};int totalCount calculateWeight(weight, count, num, count);EXPECT_EQ(totalCount, 969); } /** 原因有两个段错误是因为hash数组没有做保护被识别出来了* 另一个是输入字符串长度不够 应该将21改成100保证fgets(weightStr, 100, stdin);能够获取足够长度的字符串*//** 这个是因为weight值会大于2000使用2000判断肯定出问题啊*/ //7 //58 18 139 163 57 167 178 //1 1 3 2 6 3 4 //1711 TEST_F(googleMyTest, HJ41_6) {int count 7;int weight[] {58, 18, 139, 163, 57, 167, 178};int num[] {1, 1, 3, 2, 6, 3, 4};int totalCount calculateWeight(weight, count, num, count);EXPECT_EQ(totalCount, 1171); }/** 这个问题更明显了数量都达到2000了那肯定是array数组长度不够了*/ //10 //68 136 51 137 57 23 166 45 141 58 //3 4 6 6 4 6 2 2 1 3 TEST_F(googleMyTest, HJ41_7) {int count 10;int weight[] {68, 136, 51, 137, 57, 23, 166, 45, 141, 58};int num[] {3, 4, 6, 6, 4, 6, 2, 2, 1, 3};int totalCount calculateWeight(weight, count, num, count);EXPECT_EQ(totalCount, 2738); } //但是数组array长度改成10000还是报错请检查是否存在数组、列表等越界非法访问内存非法访问等情况 //cao,这个示例在clion上执行不会失败网页又是失败我还以为是数组越界最后突然想到是不是因为fgets获取长度不够一看果然是这样 //但是在牛客商还是有问题定位出来是count获取也有问题应该是10获取到的是1, 把语句改成fgets(countStr, 4, stdin)//10 //2000 1999 1998 1997 1996 1995 1994 1993 1992 1991 //10 10 10 10 10 10 10 10 10 10 TEST_F(googleMyTest, HJ41_8) {int count 10;int weight[] {2000, 1999, 1998, 1997, 1996, 1995, 1994, 1993, 1992, 1991};int num[] {10, 10, 10, 10, 10, 10, 10, 10, 10, 10};int totalCount calculateWeight(weight, count, num, count);EXPECT_EQ(totalCount, 16601); } //最大值为array[16600]:199550。开启的数组长度不够 //改成int array[20001] {0}; // int hash[300001] {0};//aced 通过全部用例 //运行时间 //2ms //占用内存 //1708KB工程cmakelist cmake_minimum_required(VERSION 3.16.5)message(this is cmakelist log) message(${CMAKE_CURRENT_SOURCE_DIR})get_filename_component(ProjectId ${CMAKE_CURRENT_SOURCE_DIR} NAME) message(${ProjectId}) #set(ProjectId Hello World!) message(${ProjectId}) message(NAME) string(REPLACE _ ProjectId ${ProjectId}) message(${ProjectId}) project(${ProjectId} CXX)add_definitions(-DCHENGFAMA) add_definitions(-DSTART_GOOGLETEST_MODULE)# 判断宏是否存在 if(DEFINED HELLOWORLD)message(STATUS HELLOWORLD已定义) else()message(STATUS HELLOWORLD未定义) endif()#添加宏定义Debug为CMAKE_BUILD_TYPE SET(CMAKE_BUILD_TYPE Debug)set(CMAKE_CXX_STANDARD 17)if (CMAKE_BUILD_TYPE STREQUAL Debug)set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -g -D_DEBUG) else ()set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -g -D_DEBUG) endif ()# 添加googletest库 add_subdirectory(googletest)#添加头文件 #例如include_directories(/usr/include/abc /usr/include/xxx) #是将“/usr/include/abc”和“/usr/include/xxx”这两个目录添加至编译器的头文件搜索目录(两个目录用空格分隔)。 include_directories(./include/) include_directories(./HJ41)aux_source_directory(./src Src) aux_source_directory(./gtest gtestSrc) aux_source_directory(./HJ41 HJ41Src)#通过编译源文件来创建一个可执行文件其中name是生成的可执行文件的名称source是创建可执行文件所需要的源文件。 #源文件可以使用aux_source_directory指令返回的变量将源文件保存在这个变量中,也可以是指定的.cpp文件注意路径。 add_executable(${ProjectId}${Src}${gtestSrc}${HJ41Src}arraySort.cppmain.cpp)# 链接googletest库 target_link_libraries(${ProjectId} gtest_main)我现在在想的是吗如果使用STL就不会出现这个问题吗 如果将array数组改成vector好像可以解决溢出的问题。 将hash改成hash改不了吧除非C有封装好的hash。 这里突然意识到应该将araay数组改成set才对。 总结 未完待续
http://www.w-s-a.com/news/389278/

相关文章:

  • 红酒网站设计软件设计文档
  • 如何创建网站目录网站申请支付宝接口
  • 网站做区块链然后往里面投钱品牌设计公司收费标准
  • 2022互联网+创新创业项目呼和浩特企业网站排名优化
  • 电子商务类网站建设山西自助建站系统怎么用
  • odoo做网站网站设置专栏有什么好处
  • 局域网内个人网站建设查询企业的网站有哪些
  • 网站建设属于技术开发吗网页制作团队
  • 做家常菜的网站哪个好哪个网站做图片外链
  • 眼科医院网站设计怎么做6深圳宝安是什么风险等级
  • 网站制作容易吗logo免费生成网站
  • 建设厅官方网站下载专区网络托管公司
  • 祥云平台官方网站网线制作实验原理
  • 把网站做成app的软件下载国外做兼职的网站有哪些
  • 网站建设 海豚弯专业的网站开发服务商
  • 那个网站有免费模板中国家装公司十大排名
  • 中铁建设集团有限公司门户网站余杭区建设规划局网站
  • 天猫网站建设的目标是什么做网站常见问题模板
  • 做php网站需要什么软件天津建设网官方网站
  • 南漳网站开发上海网站推广方法
  • 深圳seo网站大连旅顺房价
  • dede网站 地图什么做有没有做黑市网站
  • 做网站参考文献域名如何做网站
  • 怎么选择网站开发英文网站建设用途
  • 怎样做电子商务网站织梦生成手机网站
  • 公司网站建设选什么服务器网站里怎样添加关键词
  • 深圳建设局网站深业中城绿化项目营销型网站开发流程包括
  • 找销售的网站九江市建设项目服务中心
  • 东原ARC网站建设公司合肥seo网站推广外包
  • 那个网站是做房产中介的网站制作软件小学