Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- int a[3][3]={{1,2,3},{4,5,6},{7,8,9}},ultimacifra;
- bool corespunde(int cifra)
- {
- int i,j;
- switch(cifra)
- {
- case 1: i=0;j=0;break;
- case 2: i=0;j=1;break;
- case 3: i=0;j=2;break;
- case 4: i=1;j=0;break;
- case 5: i=1;j=1;break;
- case 6: i=1;j=2;break;
- case 7: i=2;j=0;break;
- case 8: i=2;j=1;break;
- case 9: i=2;j=2;break;
- }
- if(a[i-1][j]==ultimacifra&&i) /// N
- return true;
- if(a[i+1][j]==ultimacifra&&i<2) /// S
- return true;
- if(a[i][j-1]==ultimacifra&&j) /// V
- return true;
- if(a[i][j+1]==ultimacifra&&j<2) /// E
- return true;
- if(a[i-1][j-1]==ultimacifra&&i&&j) /// N-V
- return true;
- if(a[i+1][j+1]==ultimacifra&&i<2&&j<2) /// S-E
- return true;
- if(a[i+1][j-1]==ultimacifra&&i<2&&j) /// S-V
- return true;
- if(a[i-1][j+1]==ultimacifra&&i&&j<2) /// N-E
- return true;
- return false;
- }
- int main()
- {
- int n;
- ifstream f("smartphone1.in");
- f>>n;
- int x,c=false;
- while(n--)
- {
- f>>x;
- bool debloc=true;
- int cifra=x%10;
- ultimacifra=cifra;
- x/=10;
- while(x)
- {
- cifra=x%10;
- if(cifra==ultimacifra)
- {
- debloc=false;
- break;
- }
- if(!corespunde(cifra))
- {
- debloc=false;
- break;
- }
- ultimacifra=cifra;
- x/=10;
- }
- if(debloc)
- ++c;
- }
- ofstream g("smartphone1.out");
- g<<c<<'\n';
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment