赛码网:在线编程--约德尔测试
来源:互联网 发布:客厅沙发颜色搭配 知乎 编辑:程序博客网 时间:2024/04/28 05:58
约德尔测试
兰博和提莫闲聊之后,回归到了他们的正题,约德尔人的未来。
说起约德尔人的未来,黑默丁格曾经提出了一个约德尔测试,将约德尔人的历史的每个阶段都用一个字符表达出来。(包括可写字符,不包括空格。)。然后将这个字符串转化为一个01串。转化规则是如果这个字符如果是字母或者数字,这个字符变为1,其它变为0。然后将这个01串和黑默丁格观测星空得到的01串做比较,得到一个相似率。相似率越高,则约德尔的未来越光明。
请问:相似率为多少?
import java.text.DecimalFormat;import java.util.*;public class Yodel { public static void main(String[] args) { Scanner sin = new Scanner(System.in); String yodelString = sin.nextLine(); String target = sin.nextLine(); String translatedString = translate(yodelString); float compare = (float) compare(translatedString, target); DecimalFormat format = new DecimalFormat("0.00"); String result = format.format(compare * 100); System.out.println(result + "%"); } /** * 进行两个01串之间的比较 */ private static double compare(String str1, String str2) { char[] arr1 = str1.toCharArray(); char[] arr2 = str2.toCharArray(); int len = arr1.length; System.out.println(len); double count = 0; for (int i = 0; i < len; i++) { if (arr1[i] == arr2[i]) { count++; } } double rate = count / len; return rate; } /** * 从字符串到01串的转换 */ private static String translate(String yodelString) { if (yodelString.length() < 1 || yodelString.length() > 1000) { return ""; } char[] charArray = yodelString.toCharArray(); StringBuffer sb = new StringBuffer(); for (char c : charArray) { if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { sb.append("1"); } else { sb.append("0"); } } return sb.toString(); }}
0 0
- 赛码网:在线编程--约德尔测试
- 赛码网—在线编程(五)约德尔测试
- 在线编程测试网站
- codility 在线编程测试
- 在线编程测试平台
- 一问一答的在线编程测试题小记
- 第7周编程题在线测试
- 赛码网-在线编程:股神
- 在线测试
- 赛码网-在线编程:翻转数组
- 推荐几个很好的编程在线测试平台 online judge
- VC++编程测试QQ是否在线的简单方法
- 推荐几个很好的编程在线测试平台 online judge
- 推荐几个很好的编程在线测试平台 online judge
- 中国大学mooc编程题在线测试第四周
- 中国大学mooc编程题在线测试第五周
- 阿里实习在线编程测试--数组四等分
- 推荐几个很好的编程在线测试平台 online judge
- STAF
- 创建对象
- H5新增表单元素
- 浅谈android中的自定义封装易用的Dialog
- 一步一步超级详细的zabbix安装教程
- 赛码网:在线编程--约德尔测试
- vb.net 教程 3-4 窗体编程 公共控件3 Listbox & NumericUpDown
- android的边距问题
- 【响应式Web设计】读书笔记
- Java构造器的详解
- Classification
- Cygwin链接可执行程序的一个坑
- CSS精华记录(一)
- php实现单点登录 demo例子