Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- bool alternant(int n)
- {
- int nc=0,cif[9];
- while(n)
- cif[nc++]=n%10,n/=10;
- if(nc==1)
- return true;
- if(nc%2==0)
- return false;
- for(int i=1;i<nc-1;++i)
- if((cif[i-1]<=cif[i]&&cif[i+1]>=cif[i])||(cif[i-1]>=cif[i]&&cif[i+1]<=cif[i]))
- return false;
- return true;
- }
- int main()
- {
- int n,x;
- ifstream f("joc8.in");
- f>>n;
- int sol=0;
- for(int i=1;i<=n;++i)
- {
- f>>x;
- if(alternant(x))
- ++sol;
- }
- f.close();
- ofstream g("joc8.out");
- g<<sol;
- g.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement