a53

Smartphone1

a53
Feb 22nd, 2019
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3. int a[3][3]={{1,2,3},{4,5,6},{7,8,9}},ultimacifra;
  4.  
  5. bool corespunde(int cifra)
  6. {
  7. int i,j;
  8. switch(cifra)
  9. {
  10. case 1: i=0;j=0;break;
  11. case 2: i=0;j=1;break;
  12. case 3: i=0;j=2;break;
  13. case 4: i=1;j=0;break;
  14. case 5: i=1;j=1;break;
  15. case 6: i=1;j=2;break;
  16. case 7: i=2;j=0;break;
  17. case 8: i=2;j=1;break;
  18. case 9: i=2;j=2;break;
  19. }
  20. if(a[i-1][j]==ultimacifra&&i) /// N
  21. return true;
  22. if(a[i+1][j]==ultimacifra&&i<2) /// S
  23. return true;
  24. if(a[i][j-1]==ultimacifra&&j) /// V
  25. return true;
  26. if(a[i][j+1]==ultimacifra&&j<2) /// E
  27. return true;
  28. if(a[i-1][j-1]==ultimacifra&&i&&j) /// N-V
  29. return true;
  30. if(a[i+1][j+1]==ultimacifra&&i<2&&j<2) /// S-E
  31. return true;
  32. if(a[i+1][j-1]==ultimacifra&&i<2&&j) /// S-V
  33. return true;
  34. if(a[i-1][j+1]==ultimacifra&&i&&j<2) /// N-E
  35. return true;
  36. return false;
  37. }
  38.  
  39. int main()
  40. {
  41. int n;
  42. ifstream f("smartphone1.in");
  43. f>>n;
  44. int x,c=false;
  45. while(n--)
  46. {
  47. f>>x;
  48. bool debloc=true;
  49. int cifra=x%10;
  50. ultimacifra=cifra;
  51. x/=10;
  52. while(x)
  53. {
  54. cifra=x%10;
  55. if(cifra==ultimacifra)
  56. {
  57. debloc=false;
  58. break;
  59. }
  60. if(!corespunde(cifra))
  61. {
  62. debloc=false;
  63. break;
  64. }
  65. ultimacifra=cifra;
  66. x/=10;
  67. }
  68. if(debloc)
  69. ++c;
  70. }
  71. ofstream g("smartphone1.out");
  72. g<<c<<'\n';
  73. return false;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment