题目描述:https://pycoder.blog.csdn.net/article/details/125175834

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>struct Node {int start;int end;
};int list_index;
struct Node node_list[100];
char str_input[1000] = {0};
int vlan;void node_build(int start, int end) {node_list[list_index].start = start;node_list[list_index].end = end;list_index++;
}void str_build(int start, int end, int target) {if ((start >= target) || (end <= target)) {if (start == target) start = target + 1;if (end == target) end = target - 1;if (start > end) {return;}node_build(start, end);return;}node_build(start, target - 1);node_build(target + 1, end);
}void str_parse(char* str) {int start, end;if (strchr(str, '-') != NULL) {sscanf(str, "%d-%d", &start, &end);} else {sscanf(str, "%d", &start);end = start;}str_build(start, end, vlan);
}int myCmp(const void* a, const void* b) {struct Node* aa = (struct Node*)a;struct Node* bb = (struct Node*)b;return aa->start - bb->start;
}void myPrintf(int i, int flag) {if (node_list[i].start == node_list[i].end) {printf("%d", node_list[i].start);} else {printf("%d-", node_list[i].start);printf("%d", node_list[i].end);}if (flag == 1) {printf(",");}
}int main(void) {list_index = 0;gets(str_input);scanf("%d", &vlan);printf("%s %d\n", str_input, vlan);char* tmp = strtok(str_input, ",");str_parse(tmp);while (1) {tmp = strtok(NULL, ",");if (tmp == NULL) break;str_parse(tmp);}qsort(node_list, list_index, sizeof(node_list[0]), myCmp);for (int i = 0; i < list_index - 1; i++) {myPrintf(i, 1);}myPrintf(list_index - 1, 0);return 0;
}

华为机试C语言-VLAN资源池相关推荐

  1. 华为机试C语言-最远足迹

    题目描述:https://pycoder.blog.csdn.net/article/details/125531902 https://blog.csdn.net/weixin_44052055/a ...

  2. 华为机试C语言-找到比自己强的人数

    题目描述:https://pycoder.blog.csdn.net/article/details/127216746?spm=1001.2014.3001.5502 https://blog.cs ...

  3. 华为机试C语言-服务失效判断

    题目描述:https://zhuanlan.zhihu.com/p/526678876 https://blog.csdn.net/weixin_39765576/article/details/12 ...

  4. 华为机试C语言-整形数组按个位值排序

    题目描述:https://pycoder.blog.csdn.net/article/details/124600540 #include <stdio.h> #include <s ...

  5. 华为机试C语言-组成最大数

    题目描述:https://pycoder.blog.csdn.net/article/details/125923027 想不到这也是一道qsort的题目~ #include <stdio.h& ...

  6. 华为机试C语言-Words重量

    题目描述:https://pycoder.blog.csdn.net/article/details/124743820 #include <stdio.h> #include <s ...

  7. 华为机试C语言-篮球比赛

    题目描述:https://pycoder.blog.csdn.net/article/details/125270003?spm=1001.2014.3001.5502 动态规划 : dp[i] 表示 ...

  8. 华为机试C语言-一个正整数到Excel编号之间的转换

    题目描述:https://blog.csdn.net/qq_23934063/article/details/124676929 #include <stdio.h> #include & ...

  9. 华为机试C语言-欢乐的周末

    题目描述:https://pycoder.blog.csdn.net/article/details/125401136 递归,回溯的时候要考虑周全,不然白理解了. #include <stdi ...

最新文章

  1. 一文看尽4种SLAM中零空间的维护方法
  2. linux下怎么修改mysql的字符集编码
  3. Windows命令远程执行工具Winexe
  4. 成为优秀程序员需要具备的15种编程技巧
  5. Linux Swap空间利用率过高
  6. 牛客 - 牛半仙的妹子Tree(按询问分块+RMQ求LCA)
  7. 【Pytorch神经网络基础理论篇】 02 pytorch环境的安装
  8. linux service start|stop|restart
  9. 程序员工作5年后,在管理通道和技术通道上,如何抉择?
  10. 打包的时候不把配置文件加进去_苹果软件打包签名原理
  11. 编程分钟转化小时怎么编_贴片机编程教程,编程步骤,编程怎么编
  12. amr转换mp3格式文件
  13. 记录我的LINUX学习之路
  14. 前端常用的一些插件、UI框架、js库,样式库以及官方文档。
  15. Unity - Timeline 之Creating a Timeline Asset and Timeline instance(创建Timeline Asset和Timeline 实例)
  16. Windows文件系统过滤驱动开发教程-楚狂人
  17. 骁龙780G和骁龙888哪个好 骁龙780G和骁龙888对比,哪个更强
  18. 人不是因为有面子才牛逼,而是因为变牛逼才有面子
  19. STM32应用(八)数字温度传感器DS18B20、数字温湿度传感器DHT11(软件模拟I2C)
  20. python批量把doc文件转换成docx

热门文章

  1. 渐进算法分析(简称算法分析)详解
  2. 常见功能点测试用例大全
  3. EasyUI-DataGrid下数据库数字替换成文本信息显示以及不同状态显示不同颜色
  4. 布尔函数_布尔函数的POS和SOP形式表示
  5. Oracle一体机电源灯闪烁,24V电源模块通电后,DC OK灯闪烁,输出24v频繁通断-工业支持中心-西门子中国...
  6. TCPMP编译方法(转载)
  7. 鸿蒙系统测试失败,ANR-WatchDog-ohos: 一个简单的监测程序,可检测到鸿蒙系统的 ANR(Application Not Response-应用程序无响应)错误并引发有意义的异常...
  8. ApproximateVoxelGrid和VoxelGrid详解
  9. html5默认加载s文件夹,『总结』web前端开发常用代码整理
  10. html5游戏一笔画,一笔画得完游戏-一笔画得完官方版预约v1.0-游迅网