• 929. 独特的电子邮件地址


    class Solution {
    public int numUniqueEmails(String[] emails) {
    		HashSet<String> hs = new HashSet<String>();
    		for (int i = 0; i < emails.length; i++) {
    			StringBuffer temp = new StringBuffer();
    			int flag = 0;
    			for (int j = 0; j < emails[i].length(); j++) {
    				while (emails[i].charAt(j) == '.'&&flag==0)
    					j++;
    				if (emails[i].charAt(j) == '+')
    					while (emails[i].charAt(j) != '@') j++;
                    if(emails[i].charAt(j) == '@') flag++;
    				temp.append(emails[i].charAt(j));
    			}
    			System.out.println(temp.toString());
    			hs.add(String.valueOf(temp));
    		}
    		return hs.size();
    	}
    }
    
    
    class Solution {
    public int numUniqueEmails(String[] emails) {
    		HashSet<String> hs = new HashSet<String>();
    		for (String i : emails) {
    			int at = i.indexOf('@');                                     //用一些已知的方法来确定 并且划分 
    			StringBuffer name = new StringBuffer("");
    			for(int x = 0; x < at ; x++) {
    				if(i.charAt(x)=='+')
    					break;
    				if(i.charAt(x)=='.')
    					x++;
    				name.append(i.charAt(x));
    			}
    			name.append(i.substring(at,i.length()));
    			hs.add(String.valueOf(name));
    		}
    		return hs.size();
    	}
    }
    
  • 相关阅读:
    zznuoj 2173 春天的英雄梦
    zznuoj 2171: 春天的致富梦
    zznuoj 2169: 春天的打水梦
    zznuoj 2168 大家好 我是水题
    西安赛打铁队检讨书
    B-number HDU
    Bomb HDU
    CodeForces
    1140
    Frequent Subsets Problem
  • 原文地址:https://www.cnblogs.com/cznczai/p/11320981.html
Copyright © 2020-2023  润新知