khanhhvbde180098
Giới thiệu
include<stdio.h>
// i == 2 || i == 4 ||
int x[100];
int a[1000];
int d = 0;
void check(int n){
int i;
int num = 0;
int d0 = 0;
int d1 = 0;
for( i = 1; i <= n; i++){
if( x[i] == 0 ){
d0++;
num = num10+4;
}
if( x[i] == 1 ){
d1++;
num = num10+7;
}
}
if( d0 == d1 ){
d++;
a[d] = num;
}
}
void Try(int i,int n){
int j;
for( j = 0; j <= 1; j++ ){
x[i] = j;
if( i == n ) check(n);
if(i < 8 )Try(i+1,n);
}
}
int main(){
int i;
int n;
Try(1,2);
Try(1,4);
Try(1,6);
Try(1,8);
//for( i = 1; i <= d; i++) printf("%d\n", a[i]);
scanf("%d",&n);
if( n > a[d]) printf("4444477777");
else{
int r = d;
int l = 1;
int mid = (int)(l+r)/2;
while( l != r ){
int mid = (int)(l+r)/2;
if( n > a[mid] ){
if( n <= a[mid+1] ){
printf("%d", a[mid+1]);
break;
}
else l = mid;
}
else{
if( n > a[mid-1] ){
printf("%d", a[mid]);
break;
}
else r = mid;
}
}
}
return 0;
}