Skip to content

0012 and 0013 done in c #4511

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 69 commits into from
Jun 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
9de9aba
olution and Readme file updated with all the terms
pranjal030404 May 23, 2025
2e3bd2f
style: format code and docs with prettier
pranjal030404 May 23, 2025
4e9aab5
Update README.md
yanglbme May 23, 2025
6b22bb9
Update README_EN.md
yanglbme May 23, 2025
bb9981e
Update Solution.c
yanglbme May 23, 2025
c05b7a5
solution of 0003 done in c
pranjal030404 May 23, 2025
55bc9c9
Merge branch 'main' of https://github.com/pranjal030404/leetcode.doocs
pranjal030404 May 23, 2025
bc3ef00
0004 done in c language
pranjal030404 May 23, 2025
1358633
Merge branch 'main' into main
pranjal030404 May 23, 2025
c154596
style: format code and docs with prettier
pranjal030404 May 23, 2025
1366d3e
Merge branch 'main' into main
pranjal030404 May 25, 2025
f609530
Update README.md
yanglbme May 26, 2025
377d9dd
Update README_EN.md
yanglbme May 26, 2025
6053870
Update Solution.c
yanglbme May 26, 2025
77e281b
Update README.md
yanglbme May 26, 2025
90bb304
Update README_EN.md
yanglbme May 26, 2025
63a213f
Update Solution.c
yanglbme May 26, 2025
c207437
0005 and 0006 done in c language
pranjal030404 Jun 3, 2025
0496362
Merge branch 'main' of https://github.com/pranjal030404/leetcode.doocs
pranjal030404 Jun 3, 2025
66176ea
Merge branch 'main' into main
pranjal030404 Jun 3, 2025
db6e8f1
style: format code and docs with prettier
pranjal030404 Jun 3, 2025
67e39b5
Merge branch 'main' into main
pranjal030404 Jun 3, 2025
7c546ef
c added
pranjal030404 Jun 3, 2025
394c41d
Merge branch 'main' of https://github.com/pranjal030404/leetcode.doocs
pranjal030404 Jun 3, 2025
f4cc2cb
style: format code and docs with prettier
pranjal030404 Jun 3, 2025
7cbf92b
formatted
pranjal030404 Jun 3, 2025
d31fb66
Merge branch 'main' of https://github.com/pranjal030404/leetcode.doocs
pranjal030404 Jun 3, 2025
a304c26
Update Solution.c
yanglbme Jun 9, 2025
c7833f3
Update README.md
yanglbme Jun 9, 2025
c1744a1
Update README_EN.md
yanglbme Jun 9, 2025
abd5684
Update Solution.c
yanglbme Jun 9, 2025
a1051fa
Update README.md
yanglbme Jun 9, 2025
e085f12
Update README_EN.md
yanglbme Jun 9, 2025
0cca36a
Merge branch 'doocs:main' into main
pranjal030404 Jun 10, 2025
bca9136
Solution done for 0008 and 0009 in c language
pranjal030404 Jun 18, 2025
f997c7e
Merge branch 'doocs:main' into main
pranjal030404 Jun 18, 2025
9523135
style: format code and docs with prettier
pranjal030404 Jun 18, 2025
c86d561
Update README.md
yanglbme Jun 18, 2025
0865be2
Update README_EN.md
yanglbme Jun 18, 2025
63be5c0
Update Solution.c
yanglbme Jun 18, 2025
b50b69d
Update README.md
yanglbme Jun 18, 2025
3380c30
Update README_EN.md
yanglbme Jun 18, 2025
f2b6144
Update Solution.c
yanglbme Jun 18, 2025
32dd631
Update README.md
yanglbme Jun 18, 2025
e74cd36
Update README_EN.md
yanglbme Jun 18, 2025
acb9ee6
Solution of 0010 and 0011 in c language is done
pranjal030404 Jun 19, 2025
e02e0a6
Merge branch 'main' of https://github.com/pranjal030404/leetcode.doocs
pranjal030404 Jun 19, 2025
157f4ae
Merge branch 'main' into main
pranjal030404 Jun 19, 2025
4b3c784
style: format code and docs with prettier
pranjal030404 Jun 19, 2025
6b4f3d5
Create Solution2.c
yanglbme Jun 19, 2025
3edfb3d
Update Solution.c
yanglbme Jun 19, 2025
01e1e53
Update README.md
yanglbme Jun 19, 2025
59289cf
Update README_EN.md
yanglbme Jun 19, 2025
74f1997
Update Solution.c
yanglbme Jun 19, 2025
61bbe5f
Update README.md
yanglbme Jun 19, 2025
b5addc6
Update README_EN.md
yanglbme Jun 19, 2025
481cb58
Update README_EN.md
yanglbme Jun 19, 2025
04e664c
0012 and 0013 done
pranjal030404 Jun 20, 2025
3b9a66c
Merge branch 'main' of https://github.com/pranjal030404/leetcode.doocs
pranjal030404 Jun 20, 2025
3811cc1
Merge branch 'main' into main
pranjal030404 Jun 20, 2025
b496d54
style: format code and docs with prettier
pranjal030404 Jun 20, 2025
9af5be3
Update README.md
yanglbme Jun 20, 2025
f2beb68
Delete solution/0000-0099/0012.Integer to Roman/image.png
yanglbme Jun 20, 2025
3ef46c0
Update Solution.c
yanglbme Jun 20, 2025
a33c203
Update README.md
yanglbme Jun 20, 2025
b5b9d64
Update README_EN.md
yanglbme Jun 20, 2025
0a2e98c
Update Solution.c
yanglbme Jun 20, 2025
85da5d8
Update README.md
yanglbme Jun 20, 2025
0eaa34a
Update README_EN.md
yanglbme Jun 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions solution/0000-0099/0012.Integer to Roman/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,30 @@ class Solution {
}
```

#### C

```c
static const char* cs[] = {
"M", "CM", "D", "CD", "C", "XC",
"L", "XL", "X", "IX", "V", "IV", "I"};

static const int vs[] = {
1000, 900, 500, 400, 100, 90,
50, 40, 10, 9, 5, 4, 1};

char* intToRoman(int num) {
static char ans[20];
ans[0] = '\0';
for (int i = 0; i < 13; ++i) {
while (num >= vs[i]) {
num -= vs[i];
strcat(ans, cs[i]);
}
}
return ans;
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
24 changes: 24 additions & 0 deletions solution/0000-0099/0012.Integer to Roman/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,30 @@ class Solution {
}
```

#### C

```c
static const char* cs[] = {
"M", "CM", "D", "CD", "C", "XC",
"L", "XL", "X", "IX", "V", "IV", "I"};

static const int vs[] = {
1000, 900, 500, 400, 100, 90,
50, 40, 10, 9, 5, 4, 1};

char* intToRoman(int num) {
static char ans[20];
ans[0] = '\0';
for (int i = 0; i < 13; ++i) {
while (num >= vs[i]) {
num -= vs[i];
strcat(ans, cs[i]);
}
}
return ans;
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
19 changes: 19 additions & 0 deletions solution/0000-0099/0012.Integer to Roman/Solution.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
static const char* cs[] = {
"M", "CM", "D", "CD", "C", "XC",
"L", "XL", "X", "IX", "V", "IV", "I"};

static const int vs[] = {
1000, 900, 500, 400, 100, 90,
50, 40, 10, 9, 5, 4, 1};

char* intToRoman(int num) {
static char ans[20];
ans[0] = '\0';
for (int i = 0; i < 13; ++i) {
while (num >= vs[i]) {
num -= vs[i];
strcat(ans, cs[i]);
}
}
return ans;
}
26 changes: 26 additions & 0 deletions solution/0000-0099/0013.Roman to Integer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,32 @@ def roman_to_int(s)
end
```

#### C

```c
int nums(char c) {
switch (c) {
case 'I': return 1;
case 'V': return 5;
case 'X': return 10;
case 'L': return 50;
case 'C': return 100;
case 'D': return 500;
case 'M': return 1000;
default: return 0;
}
}

int romanToInt(char* s) {
int ans = nums(s[strlen(s) - 1]);
for (int i = 0; i < (int) strlen(s) - 1; ++i) {
int sign = nums(s[i]) < nums(s[i + 1]) ? -1 : 1;
ans += sign * nums(s[i]);
}
return ans;
}
```
<!-- tabs:end -->
<!-- solution:end -->
Expand Down
26 changes: 26 additions & 0 deletions solution/0000-0099/0013.Roman to Integer/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,32 @@ def roman_to_int(s)
end
```

#### C

```c
int nums(char c) {
switch (c) {
case 'I': return 1;
case 'V': return 5;
case 'X': return 10;
case 'L': return 50;
case 'C': return 100;
case 'D': return 500;
case 'M': return 1000;
default: return 0;
}
}

int romanToInt(char* s) {
int ans = nums(s[strlen(s) - 1]);
for (int i = 0; i < (int) strlen(s) - 1; ++i) {
int sign = nums(s[i]) < nums(s[i + 1]) ? -1 : 1;
ans += sign * nums(s[i]);
}
return ans;
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
21 changes: 21 additions & 0 deletions solution/0000-0099/0013.Roman to Integer/Solution.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
int nums(char c) {
switch (c) {
case 'I': return 1;
case 'V': return 5;
case 'X': return 10;
case 'L': return 50;
case 'C': return 100;
case 'D': return 500;
case 'M': return 1000;
default: return 0;
}
}

int romanToInt(char* s) {
int ans = nums(s[strlen(s) - 1]);
for (int i = 0; i < (int) strlen(s) - 1; ++i) {
int sign = nums(s[i]) < nums(s[i + 1]) ? -1 : 1;
ans += sign * nums(s[i]);
}
return ans;
}
Loading