当前位置:网站首页>816. fuzzy coordinates
816. fuzzy coordinates
2022-06-26 03:46:00 【Mr Gao】
816. Fuzzy coordinates
We have some two-dimensional coordinates , Such as “(1, 3)” or “(2, 0.5)”, Then we remove all commas , Decimal point and space , Get a string S. Returns all possible raw strings to a list .
There will be no extra zeros in the original coordinate representation , So there won't be anything like "00", “0.0”, “0.00”, “1.0”, “001”, "00.01" Or some other smaller number for coordinates . Besides , There is at least one number before a decimal point , So it's not going to happen “.1” Numbers in form .
The last returned list can be in any order . And notice that between the two numbers returned ( After comma ) There's a space .
Example 1:
Input : “(123)”
Output : [“(1, 23)”, “(12, 3)”, “(1.2, 3)”, “(1, 2.3)”]
Example 2:
Input : “(00011)”
Output : [“(0.001, 1)”, “(0, 0.011)”]
explain :
0.0, 00, 0001 or 00.01 It's not allowed .
Example 3:
Input : “(0123)”
Output : [“(0, 123)”, “(0, 12.3)”, “(0, 1.23)”, “(0.1, 23)”, “(0.1, 2.3)”, “(0.12, 3)”]
Example 4:
Input : “(100)”
Output : [(10, 0)]
explain :
1.0 It's not allowed .
The solution code is as follows :
/** * 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;
}
边栏推荐
- 指南针app是正规的吗?到底安不安全
- ABP framework Practice Series (II) - Introduction to domain layer
- Solve the problem that the input box is blocked by the pop-up keyboard under the WebView transparent status bar
- 虚拟化是什么意思?包含哪些技术?与私有云有什么区别?
- WebRTC系列-网络传输之6-Connections裁剪
- Comparison of static methods and variables with instance methods and variables
- MySQL stored procedure
- Classic model – RESNET
- “再谈”协议
- Qixia fire department carries out fire safety training on construction site
猜你喜欢

Comparison of static methods and variables with instance methods and variables

Classic model – RESNET

Group note data representation and operation check code

云计算基础-0

Tupu software is the digital twin of offshore wind power, striving to be the first

MySQL advanced part (IV: locking mechanism and SQL optimization)

优化——多目标规划

(15)Blender源码分析之闪屏窗口显示菜单功能

Camera-memory内存泄漏分析(三)

Nebula Graph学习篇3_多线程完成6000w+关系数据迁移
随机推荐
Andorid hide the title bar of the system
Popupwindow utility class
MySQL stored procedure
An error occurred using the connection to database 'on server' 10.28.253.2‘
Restful API interface design standards and specifications
2022.6.25 - leetcode. Un doigt d'épée. 091.
指南针app是正规的吗?到底安不安全
Click event
【Appium踩坑】io.appium.uiautomator2.common.exceptions.InvalidArgumentException: ‘capabilities‘ are mand
xml 解析bean工具类
js实现文字跑马灯效果
Worm copy construction operator overload
点击事件
WebRTC系列-网络传输之7-ICE补充之偏好(preference)与优先级(priority)
Route jump: click the operation button of the list to jump to another menu page and activate the corresponding menu
Redux thunk simple case, advantages, disadvantages and thinking
评价——层次分析
String到底能不能改变?
Cloud Computing Foundation -0
Various errors in kitti2bag installation