Advertisement
Guest User

Untitled

a guest
Jan 25th, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int toInt(string s, int i) {
  8. return stoi(string(1, s[i]));
  9. };
  10.  
  11. int _tmain(int argc, _TCHAR* argv[])
  12. {
  13. string s, v;
  14. int i, value;
  15. cout<< "Input number: ";
  16. cin>> s;
  17. value = toInt(s,0);
  18. for (i = 1;i < s.length(); i++) {
  19. switch (value) {
  20. case 0: case 3: case 6: case 9:
  21. if ((toInt(s,i) == 0) || (toInt(s,i) == 6)) value = 0;
  22. if ((toInt(s,i) == 1) || (toInt(s,i) == 7)) value = 1;
  23. if ((toInt(s,i) == 2) || (toInt(s,i) == 8)) value = 2;
  24. if ((toInt(s,i) == 3) || (toInt(s,i) == 9)) value = 3;
  25. if (toInt(s,i) == 4) value = 4;
  26. if (toInt(s,i) == 5) value = 5;
  27. break;
  28. case 1: case 4: case 7:
  29. if ((toInt(s,i) == 2) || (toInt(s,i) == 8)) value = 0;
  30. if ((toInt(s,i) == 3) || (toInt(s,i) == 9)) value = 1;
  31. if (toInt(s,i) == 4) value = 2;
  32. if (toInt(s,i) == 5) value = 3;
  33. if ((toInt(s,i) == 0) || (toInt(s,i) == 6)) value = 4;
  34. if ((toInt(s,i) == 1) || (toInt(s,i) == 7)) value = 5;
  35. break;
  36. case 2: case 5: case 8:
  37. if (toInt(s,i) == 4) value = 0;
  38. if (toInt(s,i) == 5) value = 1;
  39. if ((toInt(s,i) == 0) || (toInt(s,i) == 6)) value = 2;
  40. if ((toInt(s,i) == 1) || (toInt(s,i) == 7)) value = 3;
  41. if ((toInt(s,i) == 2) || (toInt(s,i) == 8)) value = 4;
  42. if ((toInt(s,i) == 3) || (toInt(s,i) == 9)) value = 5;
  43. break;
  44. }
  45. }
  46. cout<< s<< " mod 6 = "<< value<< endl;
  47. system("PAUSE");
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement