fork(1) download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <cctype>
  4. #include <cstring>
  5. #include <cstdio>
  6.  
  7. std::string toLower(std::string s)
  8. {
  9. for (unsigned int i = 0; i < s.size(); i++)
  10. s[i] = towlower(s[i]);
  11. return s;
  12. }
  13.  
  14. std::string toUpper(std::string s)
  15. {
  16. for (unsigned int i = 0; i < s.size(); i++)
  17. s[i] = towupper(s[i]);
  18. return s;
  19. }
  20.  
  21. int hexToInt(std::string s)
  22. {
  23. int res = 0;
  24.  
  25. for (size_t i = 0; i < s.size(); i++) {
  26. int multiplier = 1;
  27. int exp = (s.size() - 1 - i);
  28. while (exp-- > 0)
  29. multiplier *= 16;
  30. int ch = s[i];
  31. if (ch >= '0' && ch <= '9')
  32. res += multiplier * (ch - '0');
  33. else if (ch >= 'a' && ch <= 'z')
  34. res += multiplier * (ch - 'a' + 10);
  35. else if (ch >= 'A' && ch <= 'Z')
  36. res += multiplier * (ch - 'A' + 10);
  37. }
  38. return res;
  39.  
  40. }
  41.  
  42. int main () {
  43. std::cout<<"\n\n\thexToInt{0}: "<<hexToInt("0");
  44. std::cout<<"\n\n\thexToInt{1}: "<<hexToInt("1");
  45. std::cout<<"\n\n\thexToInt{2}: "<<hexToInt("2");
  46. std::cout<<"\n\n\thexToInt{3}: "<<hexToInt("3");
  47. std::cout<<"\n\n\thexToInt{4}: "<<hexToInt("4");
  48. std::cout<<"\n\n\thexToInt{5}: "<<hexToInt("5");
  49. std::cout<<"\n\n\thexToInt{6}: "<<hexToInt("6");
  50. std::cout<<"\n\n\thexToInt{7}: "<<hexToInt("7");
  51. std::cout<<"\n\n\thexToInt{8}: "<<hexToInt("8");
  52. std::cout<<"\n\n\thexToInt{9}: "<<hexToInt("9");
  53. std::cout<<"\n\n\thexToInt{A}: "<<hexToInt("A");
  54. std::cout<<"\n\n\thexToInt{B}: "<<hexToInt("B");
  55. std::cout<<"\n\n\thexToInt{C}: "<<hexToInt("C");
  56. std::cout<<"\n\n\thexToInt{D}: "<<hexToInt("D");
  57. std::cout<<"\n\n\thexToInt{E}: "<<hexToInt("E");
  58. std::cout<<"\n\n\thexToInt{F}: "<<hexToInt("F");
  59. std::cout<<"\n\n\thexToInt{10}: "<<hexToInt("10");
  60. std::cout<<"\n\n\thexToInt{11}: "<<hexToInt("11");
  61. std::cout<<"\n\n\thexToInt{12}: "<<hexToInt("12");
  62. std::cout<<"\n\n\thexToInt{13}: "<<hexToInt("13");
  63. std::cout<<"\n\n\thexToInt{14}: "<<hexToInt("14");
  64. std::cout<<"\n\n\thexToInt{15}: "<<hexToInt("15");
  65. std::cout<<"\n\n\thexToInt{16}: "<<hexToInt("16");
  66. std::cout<<"\n\n\thexToInt{17}: "<<hexToInt("17");
  67. std::cout<<"\n\n\thexToInt{18}: "<<hexToInt("18");
  68. std::cout<<"\n\n\thexToInt{19}: "<<hexToInt("19");
  69. std::cout<<"\n\n\thexToInt{1A}: "<<hexToInt("1A");
  70. std::cout<<"\n\n\thexToInt{1B}: "<<hexToInt("1B");
  71. std::cout<<"\n\n\thexToInt{1C}: "<<hexToInt("1C");
  72. std::cout<<"\n\n\thexToInt{1D}: "<<hexToInt("1D");
  73. std::cout<<"\n\n\thexToInt{1E}: "<<hexToInt("1E");
  74. std::cout<<"\n\n\thexToInt{1F}: "<<hexToInt("1F");
  75. std::cout<<"\n\n\thexToInt{20}: "<<hexToInt("20");
  76. std::cout<<"\n\n\t"<<toUpper("meu nome é c++");
  77. std::cout<<"\n\n\t"<<toLower("MEU NOME É C++")<<"\n\n";
  78. return 0;
  79. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout

	hexToInt{0}: 0

	hexToInt{1}: 1

	hexToInt{2}: 2

	hexToInt{3}: 3

	hexToInt{4}: 4

	hexToInt{5}: 5

	hexToInt{6}: 6

	hexToInt{7}: 7

	hexToInt{8}: 8

	hexToInt{9}: 9

	hexToInt{A}: 10

	hexToInt{B}: 11

	hexToInt{C}: 12

	hexToInt{D}: 13

	hexToInt{E}: 14

	hexToInt{F}: 15

	hexToInt{10}: 16

	hexToInt{11}: 17

	hexToInt{12}: 18

	hexToInt{13}: 19

	hexToInt{14}: 20

	hexToInt{15}: 21

	hexToInt{16}: 22

	hexToInt{17}: 23

	hexToInt{18}: 24

	hexToInt{19}: 25

	hexToInt{1A}: 26

	hexToInt{1B}: 27

	hexToInt{1C}: 28

	hexToInt{1D}: 29

	hexToInt{1E}: 30

	hexToInt{1F}: 31

	hexToInt{20}: 32

	MEU NOME é C++

	meu nome É c++