Skip to content

Commit 62fa2f3

Browse files
committed
Solution#7 SJ-Cipher/Edited Second Edit
1 parent 3554883 commit 62fa2f3

File tree

6 files changed

+147
-0
lines changed

6 files changed

+147
-0
lines changed

.vscode/c_cpp_properties.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "windows-gcc-x86",
5+
"includePath": [
6+
"${workspaceFolder}/**"
7+
],
8+
"compilerPath": "C:/MinGW/bin/gcc.exe",
9+
"cStandard": "${default}",
10+
"cppStandard": "${default}",
11+
"intelliSenseMode": "windows-gcc-x86",
12+
"compilerArgs": [
13+
""
14+
]
15+
}
16+
],
17+
"version": 4
18+
}

.vscode/launch.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "C/C++ Runner: Debug Session",
6+
"type": "cppdbg",
7+
"request": "launch",
8+
"args": [],
9+
"stopAtEntry": false,
10+
"externalConsole": true,
11+
"cwd": ".",
12+
"program": "build/Debug/outDebug",
13+
"MIMode": "gdb",
14+
"miDebuggerPath": "gdb",
15+
"setupCommands": [
16+
{
17+
"description": "Enable pretty-printing for gdb",
18+
"text": "-enable-pretty-printing",
19+
"ignoreFailures": true
20+
}
21+
]
22+
}
23+
]
24+
}

.vscode/settings.json

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"C_Cpp_Runner.cCompilerPath": "gcc",
3+
"C_Cpp_Runner.cppCompilerPath": "g++",
4+
"C_Cpp_Runner.debuggerPath": "gdb",
5+
"C_Cpp_Runner.cStandard": "",
6+
"C_Cpp_Runner.cppStandard": "",
7+
"C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat",
8+
"C_Cpp_Runner.useMsvc": false,
9+
"C_Cpp_Runner.warnings": [
10+
"-Wall",
11+
"-Wextra",
12+
"-Wpedantic",
13+
"-Wshadow",
14+
"-Wformat=2",
15+
"-Wcast-align",
16+
"-Wconversion",
17+
"-Wsign-conversion",
18+
"-Wnull-dereference"
19+
],
20+
"C_Cpp_Runner.msvcWarnings": [
21+
"/W4",
22+
"/permissive-",
23+
"/w14242",
24+
"/w14287",
25+
"/w14296",
26+
"/w14311",
27+
"/w14826",
28+
"/w44062",
29+
"/w44242",
30+
"/w14905",
31+
"/w14906",
32+
"/w14263",
33+
"/w44265",
34+
"/w14928"
35+
],
36+
"C_Cpp_Runner.enableWarnings": true,
37+
"C_Cpp_Runner.warningsAsError": false,
38+
"C_Cpp_Runner.compilerArgs": [],
39+
"C_Cpp_Runner.linkerArgs": [],
40+
"C_Cpp_Runner.includePaths": [],
41+
"C_Cpp_Runner.includeSearch": [
42+
"*",
43+
"**/*"
44+
],
45+
"C_Cpp_Runner.excludeSearch": [
46+
"**/build",
47+
"**/build/**",
48+
"**/.*",
49+
"**/.*/**",
50+
"**/.vscode",
51+
"**/.vscode/**"
52+
],
53+
"C_Cpp_Runner.useAddressSanitizer": false,
54+
"C_Cpp_Runner.useUndefinedSanitizer": false,
55+
"C_Cpp_Runner.useLeakSanitizer": false,
56+
"C_Cpp_Runner.showCompilationTime": false,
57+
"C_Cpp_Runner.useLinkTimeOptimization": false,
58+
"C_Cpp_Runner.msvcSecureNoWarnings": false
59+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Explanation: (Reverse Integer)
2+
3+
->First let us review the objective of the question. The main objective is to return a reversed integer or return 0 if the reversed number is greater than 2^31-1 or lesser than -2^31. So for a basic solution, we first need to store the maximum and minimum values. Then we need to store the sign of the number so that we can work with a positive number. But we need to note that if the number is -2^31, it will exceed our maximum value by 1. So here we can check and return 0 or we can create a new variable(in case of languages like C). Now we reverse the number and check if it is above or below our limit. If true then we return 0 or if within the limit we return the reversed number.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
#include<stdio.h>
3+
int reverse(int x){
4+
int MAX_INT=pow(2,31)-1;
5+
int MIN_INT=pow(-2,31);
6+
if (x==0 || (x>-10 && x<10)){
7+
return x;
8+
}
9+
int sign;
10+
if(x>=0) sign=1; else sign=-1;
11+
long int xx=labs(x);
12+
long int rev=0;
13+
while(xx){
14+
rev=rev*10 + xx%10;
15+
xx=xx/10;
16+
}
17+
if(rev*sign>MAX_INT || rev*sign<MIN_INT){
18+
return 0;
19+
}
20+
return rev*sign;
21+
22+
}
23+
24+
int main(){
25+
printf("%d",reverse(13452));
26+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
def Solution( x: int) -> int:
3+
MAX_INT=(2**31)-1
4+
MIN_INT=-2**31
5+
if -10<x<10==0:
6+
return x
7+
sign = (x)//abs(x)
8+
rev = int(str(abs(x))[::-1])
9+
if(sign==-1 and rev*sign<MIN_INT):
10+
return 0
11+
elif(sign==1 and rev>MAX_INT):
12+
return 0
13+
else:
14+
return rev*sign
15+
16+
if __name__ == "__main__":
17+
print(Solution(456))

0 commit comments

Comments
 (0)