CSU1100
来源:互联网 发布:中国骨科手术量数据 编辑:程序博客网 时间:2024/06/17 12:08
CSU1100:一二三
Description
你弟弟刚刚学会写英语的一(one)、二(two)和三(three)。他在纸上写了好些一二三,可惜有些字母写错了。已知每个单词最多有一个字母写错了(单词长度肯定不会错),你能认出他写的啥吗?
Input
第一行为单词的个数(不超过10)。以下每行为一个单词,单词长度正确,且最多有一个字母写错。所有字母都是小写的。
Output
对于每组测试数据,输出一行,即该单词的阿拉伯数字。输入保证只有一种理解方式。
Sample Input
3owetootheee
Sample Output
123
主要是用到了正则表达式
import java.util.Scanner;import java.util.regex.Pattern;public class Main {public static void main(String[] args) {// TODO Auto-generated method stubScanner in = new Scanner(System.in);int n = in.nextInt();for(int i=0;i<n;i++){String input = in.next();if(Pattern.matches("\\wne", input)||Pattern.matches("o\\we", input)||Pattern.matches("on\\w", input))System.out.println(1);else if(Pattern.matches("\\wwo", input)||Pattern.matches("t\\wo", input)||Pattern.matches("tw\\w", input))System.out.println(2);else if(Pattern.matches("\\whree", input)||Pattern.matches("t\\wree", input)||Pattern.matches("th\\wee", input)||Pattern.matches("thr\\we", input)||Pattern.matches("thre\\w", input))System.out.println(3);}in.close();}}
0 0
- CSU1100
- ubuntu 14.04 server搭建+NVIDIA+CUDA+CUDNN+caffe+theano+tensorflow+keras+matlab
- 【神经网络与深度学习】【计算机视觉】YOLO2
- Codeforces 467B Fedor and New Game
- VS2012创建和使用DLL
- 文章标题
- CSU1100
- 写string类学C++ 构造函数 重载 友元
- 2017-4-16
- effective javascript(三)——原始类型优于封装对象
- JavaScript的计时器
- k-均值算法及其实现
- 基于Java+OpnenCV的图像读取与显示
- libevent理解
- SMOJ 1767 子串个数 (AC自动机+状压DP)