Created
March 19, 2019 11:49
-
-
Save edward-hsu-1994/0ad1a07012c117c3e1a0fe8baaf90a90 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace ConsoleApp2 { | |
class Program { | |
static void Main(string[] args) { | |
int p = Rev(1000000003); | |
int p2 = FacZeroCount(50); | |
} | |
static int Rev(int input) { | |
int sign = input >= 0 ? 1 : -1; | |
int result = 0; | |
while (input != 0) { | |
try { | |
checked { | |
result = result * 10 + input % 10; | |
} | |
} catch { | |
return 0; | |
} | |
input = (int)Math.Floor(input / 10.0); | |
} | |
return result * sign; | |
} | |
static int FacZeroCount(int n) { | |
int count = 0; | |
int temp = 1; | |
for (int i = n; i > 0; i--) { | |
temp = temp * i; | |
while (temp % 10 > 0) { | |
count++; | |
temp = (int)Math.Floor(temp / 10.0); | |
} | |
} | |
return count; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment