题解 | #字符集合#

字符集合

https://www.nowcoder.com/practice/784efd40ed8e465a84821c8f3970b7b5

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
   public static int letter(char ch){
        if(ch<='Z'){
            return 1;
        }
            return 0;   
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextLine()){
        String  str=in.nextLine();
        int[] arr=new int[52];
        for(int i=0;i<str.length();i++){
            char ch=str.charAt(i);
            if(letter(ch)==1){
                arr[ch-'A'+26]++;
            }else{
                arr[ch-'a']++;
            }
        }
        for(int i=0;i<str.length();i++){
            char ch=str.charAt(i);
            if(letter(ch)==1&&arr[ch-'A'+26]!=0){
                System.out.print(ch);
                arr[ch-'A'+26]=0;
            }
            if(letter(ch)==0&&arr[ch-'a']!=0){
                System.out.print(ch);
                arr[ch-'a']=0;
            }
        }
                System.out.println();

    }
        }
      
}

全部评论

相关推荐

Cassifa:发的字比你都多的一律视为骗子或者想白嫖压榨实习生的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务