Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Validate or get the check digit of a Windows activation installation I...
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
// Validate or get the check digit of a segment of a Windows activation installation ID / confirmation ID using System; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { string idSegment = Console.ReadLine(); if (!Regex.IsMatch(idSegment, "^[0-9]+$")) { Console.Error.WriteLine("The ID segment should contain digits only"); return; } if (idSegment.Length == 6) { int[] intIdSegment = new int[6]; for (int i = 0; i < idSegment.Length; i++) { intIdSegment[i] = int.Parse(new string(idSegment[i], 1)); } if (intIdSegment[5] < 7 && (intIdSegment[0] + 2 * intIdSegment[1] + intIdSegment[2] + 2 * intIdSegment[3] + intIdSegment[4] - intIdSegment[5]) % 7 == 0) { Console.WriteLine("The ID segment is valid"); } else { Console.WriteLine("The ID segment is invalid"); } } else if (idSegment.Length == 5) { int[] intIdSegment = new int[5]; for (int i = 0; i < idSegment.Length; i++) { intIdSegment[i] = int.Parse(new string(idSegment[i], 1)); } int checkDigit = (intIdSegment[0] + 2 * intIdSegment[1] + intIdSegment[2] + 2 * intIdSegment[3] + intIdSegment[4]) % 7; Console.WriteLine("The check digit is " + checkDigit.ToString()); Console.WriteLine("The full ID segment is " + idSegment + checkDigit.ToString()); } else { Console.Error.WriteLine("Enter 5 digits to get the check digit, or enter 6 digits to validate the ID segment"); } } } }
000000
Show compiler warnings
[
-
]
Show input
Compilation time: 0,23 sec, absolute running time: 0,2 sec, cpu time: 0,22 sec, average memory usage: 18 Mb, average nr of threads: 4, absolute service time: 0,45 sec
edit mode
|
history
|
discussion
The ID segment is valid