输入一个字符串,将连续的数字字符串放到另一个二维数组中输入格式输入一个含连续数字的待提取字符串。输出格式输出提取出来的数字字符串,每个连续数字字符串占一行。样例输入 1234abc7654321[][]79869hewl98765 样例输出 1234 7654321 98765 样例说明 79869 不连续,不输出。评测用例规模与约定提取出来的连续数字字符串长度不超过 20,输入字符串内至多含有 10 个连续字符串,时间限制 1s,内存限制 256KB。(注:1287 视为整体,不属于连续数字字符串,不可被看为是 12 与 87 两个连续数字字符串。单独的数字如 1,视为连续字符串,需要加以输出)
#include<stdio.h>
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<math.h>
int continuous(char *string3){
int i=0;
int len=strlen(string3);
if (len==1){
return 1;
}
else{
int d=string3[1]-string3[0];
if (abs(d) != 1) {
return 0;
}
for (i = 1; i < len - 1; i++) { // Start from second character.
if (abs(string3[i + 1] - string3[i]) != 1) { // Check if difference between current and next characters is 1.
return 0;
}
}
}
return 1;
}
int main(){
char string[10000]={'\0'};
char string2[10][20]={'\0'};
int i=0;int j=0;int k=0;
gets(string);
while(string[i]!='\0'){
int l=0;
if(isdigit(string[i])==0){
i++;
}
else if(isdigit(string[i])!=0){
while(isdigit(string[i])!=0){
string2[j][l]=string[i];
i++;l++;
}
j++;
}
}
for(i=0;i<j;i++){
if(continuous(string2[i])==1){
printf("%s\n",string2[i]);
}
}
return 0;
}