当前位置:网站首页>816. 模糊坐标
816. 模糊坐标
2022-06-26 03:20:00 【Mr Gao】
816. 模糊坐标
我们有一些二维坐标,如 “(1, 3)” 或 “(2, 0.5)”,然后我们移除所有逗号,小数点和空格,得到一个字符串S。返回所有可能的原始字符串到一个列表中。
原始的坐标表示法不会存在多余的零,所以不会出现类似于"00", “0.0”, “0.00”, “1.0”, “001”, "00.01"或一些其他更小的数来表示坐标。此外,一个小数点前至少存在一个数,所以也不会出现“.1”形式的数字。
最后返回的列表可以是任意顺序的。而且注意返回的两个数字中间(逗号之后)都有一个空格。
示例 1:
输入: “(123)”
输出: [“(1, 23)”, “(12, 3)”, “(1.2, 3)”, “(1, 2.3)”]
示例 2:
输入: “(00011)”
输出: [“(0.001, 1)”, “(0, 0.011)”]
解释:
0.0, 00, 0001 或 00.01 是不被允许的。
示例 3:
输入: “(0123)”
输出: [“(0, 123)”, “(0, 12.3)”, “(0, 1.23)”, “(0.1, 23)”, “(0.1, 2.3)”, “(0.12, 3)”]
示例 4:
输入: “(100)”
输出: [(10, 0)]
解释:
1.0 是不被允许的。
解题代码如下:
/** * Note: The returned array must be malloced, assume caller calls free(). */
char * f1(char *sh,int len,int i,int po){
char *s=(char *)malloc(sizeof(char)*(len));
s[0]='(';
if(i==1){
s[1]=sh[i];
s[2]='\0';
return s;
}
int j;
int size=1;
if(po>=1){
for(j=1;j<po;j++){
s[size++]=sh[j];
}
if(po!=i+1){
s[size++]='.';
}
for(j=po;j<=i;j++){
s[size++]=sh[j];
}
}
s[size]='\0';
if((sh[1]=='0'&&po>2)||(sh[i]=='0'&&po<=i)){
s[0]='\0';
return s;
}
return s;
}
char * f2(char *sh,int len,int i,int po){
char *s=(char *)malloc(sizeof(char)*(len+2));
//printf("**%d %d",i,po);
if(i==len-3){
s[0]=sh[i+1];
s[1]=')';
s[2]='\0';
return s;
}
int j;
int size=0;
// printf("dfsa");
if(po>=1){
for(j=i+1;j<po;j++){
s[size++]=sh[j];
}
if(po<=len-2){
s[size++]='.';
}
for(j=po;j<=len-2;j++){
s[size++]=sh[j];
}
}
s[size]=')';
s[size+1]='\0';
if(sh[i+1]=='0'&&po>i+2||(sh[len-2]=='0'&&po<=len-2)){
s[0]='\0';
return s;
}
return s;
}
char ** ambiguousCoordinates(char * s, int* returnSize){
int len=strlen(s);
char **sp=(char **)malloc(sizeof(char *)*(len*len*len));
int i;
int size=0;
for(i=0;i<len*len*len;i++){
sp[i]=(char *)malloc(sizeof(char)*(len+6));
}
int j,k;
for(i=1;i<=len-3;i++){
int num=i;
int num2=len-2-i;
for(j=1;j<=num;j++){
char* s1=f1(s,len,i,1+j);
if(strlen(s1)==0){
continue;
}
for(k=1;k<=num2;k++){
sp[size][0]='\0';
char*s2=f2(s,len,i,k+i+1);
if(strlen(s2)==0){
continue;
}
strcat(sp[size],s1);
int l1=strlen(s1);
sp[size][l1]=',';
sp[size][l1+1]=' ';
sp[size][l1+2]='\0';
strcat(sp[size],s2);
// printf("**%s ",sp[size]);
size++;
}
}
}
*returnSize=size;
return sp;
}
边栏推荐
- Gradient
- Slide the menu of uni app custom components left and right and click switch to select and display in the middle
- Solve the problem that the uniapp plug-in Robin editor reports an error when setting the font color and background color
- Digital twin intelligent water service, breaking through the development dilemma of sponge City
- Analysis of technological changes in social robots
- Uni app Baidu cloud realizes OCR ID card recognition
- Is it safe for Caicai securities to open an account in 2022?
- 解决uniapp插件robin-editor设置字体颜色和背景颜色报错的问题
- Kotlin quick start
- Group note data representation and operation check code
猜你喜欢

Nepal graph learning Chapter 3_ Multithreading completes 6000w+ relational data migration

The role of children's programming in promoting traditional disciplines in China

The kotlin project is running normally and the R file cannot be found

Using meta analysis to drive the development of educational robot

Slide the menu of uni app custom components left and right and click switch to select and display in the middle

String到底能不能改变?

计组笔记 数据表示与运算 校验码部分

You cannot call Glide. get() in registerComponents(), use the provided Glide instance instead

【哈希表】很简单的拉链法哈希结构,以至于效果太差,冲突太多,链表太长

Group note data representation and operation check code
随机推荐
You cannot call Glide. get() in registerComponents(), use the provided Glide instance instead
MySQL高級篇第一章(linux下安裝MySQL)【下】
小程序或者for循序要不要加key?
progress bar
Preparation for wechat applet development
HL7Exception: Can‘t XML-encode a GenericMessage. Message must have a recognized struct
WebRTC系列-网络传输之6-Connections裁剪
mysql存儲過程
navicat16无线试用
Drag and drop
上传文件/文本/图片,盒子阴影
【LOJ#6718】九个太阳「弱」化版(循环卷积,任意模数NTT)
虫子 构造与析构
How to prepare for a moving wedding
Worm copy construction operator overload
Uni app swiper rotation chart (full screen / card)
Kotlin quick start
虫子 拷贝构造 运算符重载
Cultivate children's creativity under the concept of project steam Education
jupyter notebook的插件安装以及快捷键