fork download
  1. using static System.Console;
  2. using static System.Convert;
  3.  
  4. public class Program {
  5. public static void Main() {
  6. WriteLine(GenerateKey("10000"));
  7. WriteLine(GenerateKey("10011"));
  8. WriteLine(GenerateKey("10100"));
  9. WriteLine(GenerateKey("00000"));
  10. WriteLine(GenerateKey("999999999"));
  11. }
  12. public static int GenerateKey(string s) {
  13. s = s.Remove(s.Length - 1);
  14. var i = ToInt32(s);
  15. var sum = 0;
  16. while (i != 0) {
  17. sum += i % 10;
  18. i /= 10;
  19. }
  20. var somatorio = ToInt32(s) + 1;
  21. var id = somatorio.ToString();
  22. if (sum.ToString().Length > 1) sum %= 10;
  23. id += sum;
  24. return ToInt32(id);
  25. }
  26. }
  27.  
  28. //https://pt.stackoverflow.com/q/92839/101
Success #stdin #stdout 0.02s 15992KB
stdin
Standard input is empty
stdout
10011
10022
10112
10
1000000002