【244天】我爱刷题系列(3)

本文提供了一系列关于字符串处理的编程实例,包括IP地址排序、提取字符串头尾相同部分、计算字符串内数字总和及移除特定子串等任务。通过具体代码展示了不同方法的应用。

叨叨两句

  1. 未来我爱刷题系列将与跃迁之路系列绑定,同步更新,即每天我都将运用跃迁之路的方法进行刻意练习。
  2. 总结套路,用乘法思路跃迁。

题8:编写程序把这些IP按数值大小,从小到大排序并打印出来

编写程序把这些IP按数值大小,从小到大排序并打印出来。
61.54.231.245 61.54.231.9 61.54.231.246 61.54.231.48 61.53.231.249

方法1:用循环嵌套进行二次切割

package com.heima_xxxxxxxxx;

import java.util.ArrayList;
import java.util.Collections;

public class Test5_4 {
    public static void main(String[] args) {
        mySort("61.54.231.245 61.54.231.9 61.54.231.246 61.54.231.48 61.53.231.249");
    }
    
    public static void mySort(String str) {
        ArrayList<Integer> list = new ArrayList<>(); 
        String[] arr1 = str.split(" ");
        for(String sTemp1 : arr1) {
            String[] arr2 = sTemp1.split("\\.");
            for(String sTemp2 : arr2) {
                list.add(Integer.parseInt(sTemp2));
            } 
        }
        Collections.sort(list);
        System.out.println(list);
    }
    
}

方法2:用正则实现一次切割

package com.heima_xxxxxxxxx;

import java.util.ArrayList;
import java.util.Collections;
public class Test5_4 {
    public static void main(String[] args) {
        mySort("61.54.231.245 61.54.231.9 61.54.231.246 61.54.231.48 61.53.231.249");
    }
    
    public static void mySort(String str) {
        ArrayList<Integer> list = new ArrayList<>(); 
        String[] arr1 = str.split("[^0-9]");//或使用\\D
        for(String s : arr1) {
            list.add(Integer.parseInt(s));
        }
        Collections.sort(list);
        System.out.println(list);
    }
    
}

题9:给定一字符串,截取出该字符串开头和结尾相同的内容且不可重叠,并返回

题目描述:

书写一个类,类名为Itheima;

类中有一个方法,方法名sameEnds;

给定一字符串,截取出该字符串开头和结尾相同的内容且不可重叠,并返回。
例如:("javaXYZjava") -> "java",否则返回空。

提示:

方法调用期望值
sameEnds("abXYab")"ab"
sameEnds("xx")"x"
sameEnds("xxx")"x"
package com.heima_6;

public class Itheima_01 {

    public String sameEnds(String str) {
        //遍历字符
        //索引0字符串 尝试 endsWith  
            //为true 则截取返回
            //为false pass
        //索引0 + 1字符串 尝试endsWith
        //。。。
        //一直尝试到0+1+...+length-2索引字符(不能尝试倒数第1个了)
    
        String newStr = "";
        for(int i = 0; i < str.length() - 1 ; i++) {
            newStr = newStr + str.charAt(i);
            if(str.endsWith(newStr)) {
                return newStr;
            }
        }
        
        return "";
        
    }

}
package com.heima_6;

public class Test_01 {

    public static void main(String[] args) {
        Itheima_01 it = new Itheima_01();
        
        System.out.println(it.sameEnds("abXYab"));
        System.out.println(it.sameEnds("xx"));
        System.out.println(it.sameEnds("xxx"));
    }

}

题10: 给定一字符串,求出现在字符串中的数字之和

题目描述:

书写一个类,类名为Itheima;

类中有一个方法,方法名sumNumbers;

给定一字符串,求出现在字符串中的数字之和。
例如:sumNumbers("abc123xyz") → 123

提示:

方法调用期望值
sumNumbers("abc123xyz")123
sumNumbers("aa11b33")44
sumNumbers("7 11")18
package com.heima_3;

public class Itheima_07 {
    public int sumNumbers(String str) {
        int sum = 0;
        String regex = "\\D+";
        String[] arr = str.split(regex);
        
        for(String s : arr) {
            if(s.length() != 0) {
                sum = sum + Integer.parseInt(s);
            }
        }
        return sum;
    }
}
package com.heima_3;

public class Test_07 {
    public static void main(String[] args) {
        Itheima_07 it = new Itheima_07();
        System.out.println(it.sumNumbers("abc123xyz")); 
        System.out.println(it.sumNumbers("aa11b33")); 
        System.out.println(it.sumNumbers("7 11")); 
    }
}

题11: 移除指定的字符串

题目描述:

书写一个类,类名为Itheima;

类中有一个方法,方法名withoutString;

给定两个字符串参数base和remove,返回删除了remove字符串的base字符串(不区分大小写),
并且返回的base字符串不含有remove的重叠事例。
例如:("This is a FISH", "IS") -> "Th a FH" (注意Th和a之间有两个空格哦)
注意: 期望值里的一个空格可以代表多个空格.

提示:

方法调用 期望值
withoutString("Hello there","llo") "He there"
withoutString("Hello there","e") "Hllo thr"
withoutString("Hello there","x") "Hello there"

方法1

package com.heima_6;

public class Itheima_07 {

    public String withoutString(String base,String remove) {
        String newStr = base.replaceAll(remove,"");
        return newStr;
        
    }
}

方法2

package com.heima_6;

public class Itheima_07 {

    public String withoutString(String base,String remove) {
        for(int i = 0; i <= base.length() - remove.length(); i++) {
            String newStr = base.substring(i, i + remove.length());
            if(newStr.equalsIgnoreCase(remove)) {
                base = base.replace(newStr, "");
            }
        }
        return base;
    }
}
package com.heima_6;

public class Test_07 {

    public static void main(String[] args) {
        Itheima_07 it = new Itheima_07();
        System.out.println(it.withoutString("Hello there", "llo"));
        System.out.println(it.withoutString("Hello there", "e"));
        System.out.println(it.withoutString("Hello there", "x"));
    }

}
<think>好的,用户想找抖音上《我发明》系列使用的配乐名称。首先需要明确《我发明》是什么节目,可能涉及的音乐类型。然后考虑在抖音上常用的配乐来源,可能是节目原声或流行音乐。 需要调用搜索工具,查找相关关键词,比如“抖音 我发明 背景音乐”、“我发明配乐名称”等。查看是否有用户讨论或官方信息。注意可能存在多个配乐的情况,不同片段使用不同音乐。 整合搜索结果,发现《我发明》常用背景音乐包括《HandClap》《Tassel》《Go Time》等。需要确认这些是否在抖音上被广泛使用。同时,用户可能需要区分节目原声和抖音用户自选的音乐,所以需要说明不同情况下的查找方法。 另外,提供识别音乐的方法,比如使用抖音的识别功能或第三方应用Shazam。步骤要简明,分点说明,避免使用顺序词汇。确保回答符合格式要求,公式和代码部分若有的话要正确标注,但此处可能不需要。最后生成相关问,需基于原问,如其他节目配乐、识别音乐方法、节目播出时间等。</think>《我发明》在抖音传播时常用配乐需根据具体视频内容判断。通过以下方式可精准识别配乐名称: **方法一:节目原声匹配** 《我发明》央视原版背景音乐多采用科技感电子音乐,部分片段使用《HandClap》(Fitz and The Tantrums乐队)或《Tassel》(Cymophane创作)等曲目。可对比原节目片头片尾音乐进行验证 **方法二:抖音音乐识别功能** 打开目标短视频,点击右下角旋转唱片图标进入音乐页面,查看“原声”标签显示的配乐名称。若被二次剪辑,需使用“Shazam”等第三方应用实时识别:启动Shazam后靠近音源,10秒内显示识别结果 **方法三:关键词组合搜索** 在抖音搜索框输入“我发明 背景音乐”“我发明BGM”等组合关键词,查看高赞视频评论区。创作者常会在置顶评论注明配乐信息,例如《Go Time》(Mark Petrie)常见于发明过程加速片段 ```python # 示例:使用ShazamAPI识别音频 import shazamio from shazamio import Shazam async def identify_music(file_path): shazam = Shazam() result = await shazam.recognize_song(file_path) return result[&#39;track&#39;][&#39;title&#39;] ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值