Skip to content

Commit 4341bec

Browse files
committed
Merge pull request xxg1413#30 from willalways/master
No.xx
2 parents 8df869d + def8161 commit 4341bec

File tree

17 files changed

+452
-0
lines changed

17 files changed

+452
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"aa"
2+
"a"
3+
4+
"aa"
5+
"aa"
6+
7+
"aaa"
8+
"aa"
9+
10+
"aa"
11+
"a*"
12+
13+
"aa"
14+
".*"
15+
16+
"ab"
17+
".*"
18+
19+
"aab"
20+
"c*a*b"
21+
22+
"aaa"
23+
"ab*a*c*a"
24+
25+
26+
"abcdede"
27+
"ab.*de"
28+
29+
"a"
30+
"ab*"
31+
32+
"ab"
33+
".*c"
34+
35+
"ab"
36+
".*.."
37+
38+
"bbab"
39+
"b*a*"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
#include <ctype.h>
5+
#include <math.h>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include "head.h"
2+
char *nextlogiceq(char s, char *p)
3+
{
4+
if (!*p) return NULL;
5+
if (*p == '.' || s == *p) return p;
6+
if (p[1] == '*') return nextlogiceq(s, p + 2);
7+
return NULL;
8+
}
9+
10+
int isMatch(char* s, char* p)
11+
{
12+
while (*p && *s) {
13+
if (p[1] != '*') {
14+
if (*p == '.' || *s == *p)
15+
p++,s++;
16+
else
17+
return 0;
18+
} else {
19+
if (*p != '.' && *s != *p) {
20+
p += 2;
21+
continue;
22+
}
23+
char *tmp = nextlogiceq(*s, p + 2);
24+
if (tmp)
25+
if (isMatch(s, tmp)) return 1;
26+
s += 1;
27+
continue;
28+
}
29+
}
30+
31+
if (*s) return 0;
32+
while (*p)
33+
if (p[1] == '*') p+=2;
34+
else return 0;
35+
return 1;
36+
}
37+
38+
int main(int argc, char *argv[])
39+
{
40+
char s[] = {"bbab"};
41+
char p[] = {"b*a*"};
42+
printf("%d\n", isMatch(s, p));
43+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#define MIN(x,y) ((x) > (y)? (y) : (x))
2+
int maxArea(int* height, int heightSize)
3+
{
4+
int area = 0;
5+
int maxi, max = 0;
6+
int i, j, k;
7+
for (i = 0; i < heightSize; i++)
8+
if (height[i] > max) {
9+
max = height[i];
10+
maxi = i;
11+
}
12+
13+
for (i = 0; i <= maxi; i++) {
14+
for (j = heightSize - 1; j >= maxi; j--) {
15+
k = MIN(height[i], height[j]) * (j - i);
16+
if (k > area) area = k;
17+
}
18+
}
19+
return area;
20+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "head.h"
2+
#define MIN(x,y) ((x) > (y)? (y) : (x))
3+
4+
int maxArea(int* height, int heightSize)
5+
{
6+
int area = 0, k;
7+
int i = 0, j = heightSize - 1;
8+
while (i < j) {
9+
k = MIN(height[i], height[j]) * (j - i);
10+
if (k > area) area = k;
11+
if (height[i] <= height[j]) i++;
12+
else j--;
13+
}
14+
return area;
15+
}
16+
17+
int main(int argc, char *argv[])
18+
{
19+
int i[] = {1, 3, 5, 7, 9};
20+
printf("%d\n", maxArea(i, 5));
21+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
#include <ctype.h>
5+
#include <math.h>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include "head.h"
2+
int lt1000(char *result, int num, int level, char n1, char n2, char n3)
3+
{
4+
int k = 0;
5+
while (num >= level) {
6+
if (num >= 9 * level) {
7+
result[k++] = n1;
8+
result[k++] = n3;
9+
num -= 9 * level;
10+
} else if(num >= 5 * level) {
11+
result[k++] = n2;
12+
num -= 5 * level;
13+
} else if(num >= 4 * level) {
14+
result[k++] = n1;
15+
result[k++] = n2;
16+
num -= 4 * level;
17+
} else if(num >= level) {
18+
while (num >= level) {
19+
result[k++] = n1;
20+
num -= level;
21+
}
22+
}
23+
}
24+
return k;
25+
}
26+
char* intToRoman(int num)
27+
{
28+
int k = 0;
29+
static char out[16];
30+
while (num >= 1000) {
31+
out[k++] = 'M';
32+
num -= 1000;
33+
}
34+
if(num >= 100) k += lt1000(out + k, num % 1000, 100, 'C', 'D', 'M');
35+
if(num >= 10) k += lt1000(out + k, num % 100, 10, 'X', 'L', 'C');
36+
if(num >= 1) k += lt1000(out + k, num % 10, 1, 'I', 'V', 'X');
37+
out[k] = 0;
38+
return out;
39+
}
40+
41+
int main(int argc, char *argv[])
42+
{
43+
//printf("%s\n", intToRoman(atoi(argv[1])));
44+
printf("%s\n", intToRoman(1000));
45+
return 0;
46+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
#include <ctype.h>
5+
#include <math.h>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include "head.h"
2+
int romanToInt(char* s)
3+
{
4+
int ret = 0;
5+
int alpha[26] = {0};
6+
alpha['I' - 'A'] = 1;
7+
alpha['V' - 'A'] = 5;
8+
alpha['X' - 'A'] = 10;
9+
alpha['L' - 'A'] = 50;
10+
alpha['C' - 'A'] = 100;
11+
alpha['D' - 'A'] = 500;
12+
alpha['M' - 'A'] = 1000;
13+
while (*s && *s == 'M') {
14+
ret += 1000;
15+
s++;
16+
}
17+
while (*s && s[1]) {
18+
if (alpha[s[0] - 'A'] < alpha[s[1] - 'A']) {
19+
ret += alpha[s[1] - 'A'] - alpha[s[0] - 'A'];
20+
s += 2;
21+
} else {
22+
ret += alpha[s[0] - 'A'];
23+
s ++;
24+
}
25+
}
26+
if (*s) ret += alpha[s[0] - 'A'];
27+
return ret;
28+
}
29+
30+
int main(int argc, char *argv[])
31+
{
32+
return printf("%d\n", romanToInt(argv[1]));
33+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
#include <ctype.h>
5+
#include <math.h>

0 commit comments

Comments
 (0)