asu
BAN USERpublic class Main {
public static void main(String[] args) {
int no_of_beds = 3 ;
int no_of_possible_beds = 0 ;
byte[] TestBed = new byte[] {0,1,0,0,0,0,0,1,0,0};
for (int i = 0; i < TestBed.length; i++) {
// approach1:for each 1, skip one i and see if we have zero in i+2,
// if yes, assign the Flower in i+2
/*if( TestBed[i] == 1 && (i+2 <TestBed.length) && TestBed[i+2] == 0) {
//TestBed[i+2] = 1; // this step is must for this approch
no_of_possible_beds++;
}*/
// approach2:for two consecutive zeros, we can increase the
// no_of_possible_beds
// also skip the recent zero.Note below code is with no replacement in TestBed.
// We just estimate the possibility of fitting
if(TestBed[i]== 0 && i-1 >= 0 && TestBed[i-1] == 0) {
no_of_possible_beds ++ ;
i++;
}
}
System.out.print(no_of_possible_beds >= no_of_beds? true:false);
}
}
- asu June 03, 2015public class Main {
public static void main(String[] args) {
int no_of_beds = 3 ;
int no_of_possible_beds = 0 ;
byte[] TestBed = new byte[] {0,1,0,0,0,0,0,1,0,0};
for (int i = 0; i < TestBed.length; i++) {
// approach1:for each 1, skip one i and see if we have zero in i+2,
// if yes, assign the Flower in i+2
/*if( TestBed[i] == 1 && (i+2 <TestBed.length) && TestBed[i+2] == 0) {
//TestBed[i+2] = 1; // this step is must for this approch
no_of_possible_beds++;
}*/
// approach2:for two consecutive zeros, we can increase the no_of_possible_beds and
// also skip the recent zero.Note below code is with no replacement in TestBed.
// We just estimate the possibility of fitting
if(TestBed[i]== 0 && i-1 >= 0 && TestBed[i-1] == 0) {
no_of_possible_beds ++ ;
i++;
}
}
System.out.print(no_of_possible_beds >= no_of_beds? true:false);
}
}
public class Main {
public static void main(String[] args) {
// input
String input = "LavenderFarms";
// for all the char in the input, except the start and end, we will look up input char and
// append it to the result
StringBuilder result_sb = new StringBuilder();
int Factor = input.length() - 2;
result_sb.append(input.toCharArray()[0]);
for(int i=1; i < input.length(); i++){
System.out.println(result_sb.toString()
+ ( Factor > 0 ? Integer.toString(Factor) : "" )
+ input.toCharArray()[input.length() - 1]);
Factor -- ;
result_sb.append(input.toCharArray()[i]);
}
}
}
- asu June 03, 2015