LUCKY STRING
来源:互联网 发布:ubuntu启动引导器设置 编辑:程序博客网 时间:2024/06/11 14:36
题目描述
A string s is LUCKY if and only if the number of different characters in s is a fibonacci number. Given a string consisting of only lower case letters , output all its lucky non-empty substrings in lexicographical order. Same substrings should be printed once.
输入描述:
a string consisting no more than 100 lower case letters.
输出描述:
output the lucky substrings in lexicographical order.one per line. Same substrings should be printed once.
输入例子:
aabcd
输出例子:
a aa aab aabc ab abc b bc bcd c cd d
import java.util.HashSet;import java.util.Scanner;import java.util.Set;import java.util.TreeSet;public class Main {private TreeSet<String> result = new TreeSet<String>();private Set<Integer> fn = new HashSet<Integer>();public static void main(String[] args) {// TODO Auto-generated method stubScanner reader = new Scanner(System.in);String str = reader.next();if(str==null||"".equals(str)) return;Main ls = new Main();ls.luckNumber(str);}public void luckNumber(String str){ char[] tmp = str.toCharArray(); int n = tmp.length; calFn(n); for(int i=0; i<n; ++i){ for(int j=1; i+j<=n; ++j){ String t = new String(tmp, i, j); if(!result.contains(t)){ if(isLuckNumber(t)){ result.add(t); } } } } for(String w : result){ System.out.println(w); } } private boolean isLuckNumber(String str){ Set<Character> set = new HashSet<Character>(); for(int i=0;i<str.length();++i){ set.add(str.charAt(i)); } int len = set.size(); if(fn.contains(len)){ return true; }else{ return false; } } public void calFn(int n){ fn.add(1); int a = 1; int b = 1; int c = 0; for(int i=2;i<=n;++i){ c = a + b; fn.add(c); a = b; b = c; } }}
0 0
- lucky string
- LUCKY STRING
- Lucky String
- Lucky String
- LUCKY STRING
- Lucky String
- LUCKY STRING
- LUCKY STRING
- Lucky String
- B. Lucky String
- 微软 LUCKY STRING
- 【微软】LUCKY STRING
- 算法笔试题:LUCKY STRING
- Codeforces 110B-Lucky String(技巧)
- 【string】#84 A. Nearly Lucky Number
- lucky
- Lucky draw
- Lucky Word
- Java学习·设计模式
- webView 点击方法与返回方法
- Comet4J(Comet for Java)是一个纯粹基于AJAX(XMLHTTPRequest)的服务器推送框架,消息以JSON方式传递,具备长轮询、长连接、自动选择三种工作模式。
- WinRAR 5.1-5.3 64位注册方法,rarreg.key
- Kendo UI常用示例汇总(四)
- LUCKY STRING
- App版本更新时对SQLite数据库升级或者降级遇到的问题
- 四、设置信任
- 【poj 3368】Frequent values 题意&题解&代码(C++)
- setContentView() 报 OutOfMemoryError的错误
- struts2中拦截器的原理与配置
- android txt小说阅读器的实现
- 递归
- 【poj 3368 】 Frequent values 线段树应用