Skip to content

Instantly share code, notes, and snippets.

@fazd
Created August 16, 2017 05:10
Show Gist options
  • Save fazd/2d7f164f64a4a609c6eacbc621f333be to your computer and use it in GitHub Desktop.
Save fazd/2d7f164f64a4a609c6eacbc621f333be to your computer and use it in GitHub Desktop.
package alpaca;
public class Alpaca {
public static String elec(char str){
if(str=='A')
return "AL";
if(str=='L')
return "PACA";
if(str=='P')
return "CP";
if(str=='C')
return "PC";
return "";
}
public static String formation(String str){
String total="";
for(int i=0; i<str.length(); i++){
total=total+elec(str.charAt(i));
}
return total;
}
public static int cont(String str){
int tot=0;
for(int i=0; i<str.length()-5; i++){
if(str.substring(i, i+6).equals("ALPACA")){
tot++;
}
}
return tot;
}
public static void main(String[] args) {
String A= "A";
int tot;
for (int i=1; i<=10; i++){
A=formation(A);
tot=cont(A);
System.out.println("I="+i);
System.out.println("TOT="+tot);
//System.out.println(A);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment