vps网站助手,网站开发与维修是什么意思,网站制作蒙特,南宁网站开发推广目录 题目
代码
测试用例
the input
the correct output
问题发现过程阐述
如果把line16中的数组大小11换成line17中的10
case 1
case 2
case 3
如果数组开成11
case4
代码分析
问题描述
Question1
Question2 题目 题目#xff1a;连续数字字符串提取 问题描述…目录 题目
代码
测试用例
the input
the correct output
问题发现过程阐述
如果把line16中的数组大小11换成line17中的10
case 1
case 2
case 3
如果数组开成11
case4
代码分析
问题描述
Question1
Question2 题目 题目连续数字字符串提取 问题描述 输入一个字符串将连续的数字字符串放到另一个二维数组中 输入格式 输入一个含连续数字的待提取字符串。 输出格式 输出提取出来的数字字符串每个连续数字字符串占一行。 样例输入 1234abc7654321[][]79869hewl98765 样例输出 1234 7654321 98765 样例说明 79869不连续不输出。 评测用例规模与约定 提取出来的连续数字字符串长度不超过20输入字符串内至多含有10个连续字符串 时间限制1s内存限制256KB。注1287视为整体不属于连续数字字符串不可被看 为是12与87两个连续数字字符串。单独的数字如1视为连续字符串需要加以输出 代码
#include stdio.h
#include stdlib.h
#include ctype.hshort continuity_judge(char * s,short n);
int main()
{char s[211] ;gets(s);typedef struct{char nums[21];short total;}STRINGS;STRINGS strings[11];//STRINGS strings[10];short index 0,i 0;//extractionfor(char *p s;*p;p){while(*p isdigit(*p)){strings[index].nums[i] *p;}if(i){strings[index].total i;strings[index].nums[i] \0;i 0;index;}}//judge and outputfor(i 0;i index;i){if(continuity_judge(strings[i].nums,strings[i].total)){puts(strings[i].nums);}}return 0;
}
short continuity_judge(char * s,short n)
{if(n 1)return 1;short deta s[1] - s[0];if(deta ! 1 deta ! -1 )return 0;for(int i 1;i n-1;i){if(s[i1] - s[i] ! deta)return 0;}return 1;
}测试用例
the input 421932__123nxoq81x01u3123xq0981d80192j81028!93121238ydiqw123jdw1cu012 the correct output 2 123 01 3 123 123 1 012 问题发现过程阐述
问题在line16line17
如果把line16中的数组大小11换成line17中的10
case 1
输入 421932__123nxoq81x01u3123xq0981d80192j81028!93121238ydiqw123jdw1cu012 输出就变成了 2 123 01 3 123 123 1 0 最后一项少了12
并且通过调试这一项在strings数组最后一项的nums字符串里确实被存成了0证明12未被读入
case 2
如果输入少进一个字符 21932__123nxoq81x01u3123xq0981d80192j81028!93121238ydiqw123jdw1cu012 输出就 2 123 01 3 123 123 1 01 多读进来一个
case 3
再少输入进一个字符 1932__123nxoq81x01u3123xq0981d80192j81028!93121238ydiqw123jdw1cu012 输出 2 123 01 3 123 123 1 012 正常了
如果数组开成11
case4
输入 421932__123nxoq81x01u3123xq0981d80192j81028!93121238ydiqw123jdw1cu012 输出 2 123 01 3 123 123 1 012 正常了
代码分析
仔细解读代码后发现其实strings[]数组开得有问题这个输入中有14个数字串数组开得不够大
问题描述
Question1
为什么数组开到11就正常了明明有14个数字串按理来说即使改成11后面三个应该无法读入才对
Question2
为什么在数组开到10时会出现这种最后几个字符没被读入改变输入序列长度就能读进去的情况
这看着反倒像是s[]数组开得不够大但实际是s[]开得足够大了