Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <math.h>
- #define max 1000
- int sodep(int a)
- {
- int i,b[max],c[max],len=0,count1=0,count2=0;
- while (a!=0)//cho cac chu so vao mang b
- {
- b[len]=a%10;
- a/=10;
- len++;
- }
- for (i=0;i<len;i++)
- c[i]=b[i];
- for (i=0;i<len;i++)//dao nguoc lai mang b de so sanh
- b[i]=c[len-i-1];
- for (i=0;i<len-1;i++)//123 thi so sanh tu 1 voi 2, 2 voi 3
- {
- if (b[i+1]==b[i]+1)
- count1++;
- else if (b[i+1]==b[i]-1)
- count1++;
- else //neu ko giam hoac tang dan thi break, return 0
- {
- count2++;
- break;
- }
- }
- if (count2!=0)
- return 0;
- else return 1;
- }
- int main()
- {
- int n,j,dem=0;
- scanf("%d",&n);
- for (j=pow(10,n-1);j<=pow(10,n);j++)
- if(sodep(j)==1)
- dem++;
- printf("%d",dem);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement