头像

青影


访客:48

离线:2小时前



青影
7天前

java 代码

import java.util.Scanner;
class Main{
   static String[] nums=new String[]{"zero","one","two","three","four","five","six","seven","eight","nine"};
   static String[] cnts=new String[]{"","","double","triple","quadruple","quintuple","sextuple","septuple","octuple","nonuple","decuple"}; 

    static void print(String s1) {
        char[] s = s1.toCharArray();
        for (int i=0;i<s1.length();i++) {//遍历这个字符串
            int j=i+1;
            while (j<s1.length() && s[i]==s[j]) j++;//计算重复的数
            int len=j-i;
            if (len >=2 && len<=10) System.out.print(cnts[len]+" "+nums[s[i]-'0']+" ");
            else if (len>10) {
                for (int k=0;k<len;k++) {
                    System.out.print(nums[s[i]-'0']+" ");
                }
            }
            else System.out.print(nums[s[i]-'0']+" ");
            i=j-1;//更新i的位置
        }
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();    //读入共有多少组测试数据
        for(int c = 1;c<=T;c++){  //对每组数据进行操作
            String s = sc.next();  //读入前面的字符串

            String seq1 = sc.nextLine(); //读入后面的
            String seq = seq1.trim();    //去掉前面的空格
            //System.out.println(seq);

            String[] e = seq.split("-");  //分离出每个数字
            int[] len = new int[e.length]; //将分离出的数字放入数组中,备用
            for(int i =0;i<len.length;i++){

               len[i] = Integer.parseInt(e[i]); //将string转为int存入数组
                //System.out.println(len[i]);
            }
            System.out.print("Case #" + c+":  ");

            int start = 0;
            for(int l : len){
                print(s.substring(start,start+l));//先对前几个数进行操作
                start+=l;
            }
            System.out.println();
        }
    }
}



青影
8天前
import java.util.Scanner;
class Main{
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){ 

            int n = sc.nextInt();
            int m = sc.nextInt();
            int[][] dp = new int[101][11];
             for(int i = 1;i<=n;i++){
                for(int j=1;j<=m;j++){
                    dp[i][j] = dp[i-1][j] + dp[i-1][j-1] +1;
                }
                if(dp[i][m]>=n){
                    System.out.println(i);
                    break;
                }
            }
        }
    }
}