結果
問題 | No.170 スワップ文字列(Easy) |
ユーザー |
![]() |
提出日時 | 2016-01-28 23:06:01 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 57 ms / 5,000 ms |
コード長 | 1,338 bytes |
コンパイル時間 | 2,429 ms |
コンパイル使用メモリ | 78,616 KB |
実行使用メモリ | 37,316 KB |
最終ジャッジ日時 | 2024-12-23 00:35:00 |
合計ジャッジ時間 | 4,613 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.HashMap; public class Main { public static void main(String[] args) { BufferedReader stdReader =new BufferedReader(new InputStreamReader(System.in)); try { String line = stdReader.readLine(); HashMap<Character, Integer> hashMap = new HashMap<>(); ArrayList<Character> charList = new ArrayList<>(); for(int i=0;i<line.length();i++){ if(!hashMap.containsKey(line.charAt(i))){ hashMap.put(line.charAt(i), 1); charList.add(line.charAt(i)); }else{ int num = hashMap.get(line.charAt(i)); hashMap.remove(line.charAt(i)); hashMap.put(line.charAt(i), num+1); } } int ans = 1; int n = line.length(); for(int i=0;i<charList.size();i++){ ans *= comb(n, hashMap.get(charList.get(i))); n -= hashMap.get(charList.get(i)); } System.out.println(ans-1); } catch (IOException e) { e.printStackTrace(); } } public static int comb(int n,int r){ int temp1 = 1; int temp2 = 1; int loop = r; for(int i=0;i<loop;i++){ temp1 *= n--; temp2 *= r--; } return temp1/temp2; } }