Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
isbn
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { //Your code goes here //"978-0-306-40615-?"; var code = "97807 35623 87?"; var isbn = new ISBN(code); } } public class ISBN { public ISBN(string code) { //prefix element, registration group, registrant, publication and check digit string str;// string holder int i = 0; // iterator for the looop int s = 0; // s is the checksum digit List<int> j = new List<int>(); str = Regex.Replace(code, @"[?]","0"); // Replace '?' with '0' str = Regex.Replace(str, @"[^0123456789?]", string.Empty); // Remove non digits // Error check length if(str.Length != 10 && str.Length != 13) Console.Write("Error {0} of digits is invalid isbn\n", str.Length); foreach(char c in str) { int n = Int32.Parse(c.ToString()); //s = 9×1 + 7×3 + 8×1 + 0×3 + 3×1 + 0×3 + 6×1 + 4×3 + 0×1 + 6×3 + 1×1 + 5×3 // = 9 + 21 + 8 + 0 + 3 + 0 + 6 + 12 + 0 + 18 + 1 + 15 // = 93 // 93 / 10 = 9 remainder 3 //10 – 3 = 7 if(IsEven(i)) s += n * 1; else s += n * 3; //Console.WriteLine("Iseven -> " + i.ToString()); //Console.Write("{0}\n", n.ToString()); i++; } s = (10 - (s % 10)) % 10; Console.WriteLine("result $s == " + s.ToString()); Console.Write("$str == {0}\n", str); } private bool IsOdd(int val) => val % 2 != 0; private bool IsEven(int val) => val % 2 == 0; } }
run
|
edit
|
history
|
help
0
Fiddling around
Student Management System
sadfghjklö
Olymp
Date Diff
1
actions and tasks
asdxasxasdf
asxasx sxa
Byte array to base 64 string