なにか

Paizaの単語のカウント回答

Paizaの単語のカウント回答

  • タグ:
  • タグはありません
//C#
using System;
using System.Collections.Generic;

class Program{
	static void Main(){
		var words=Console.ReadLine()
			.Trim()
			.Split(' ');
		var wordCount=new Dictionary<string,int>();
		foreach(var word in words){
			if(wordCount.ContainsKey(word)){
				wordCount[word]++;
			}
			else{
				wordCount.Add(word,1);
			}
		}
		foreach(var v in wordCount){
			Console.WriteLine($"{v.Key} {v.Value}");
		}
	}
}

//JavaScript
const rl=require("readline").createInterface(process.stdin);

const g=function*(){
	var words=(yield rl.once("line",v=>g.next(v)))
		.trim()
		.split(" ");
	var wordCount=new Map();
	for(let word of words){
		if(wordCount.has(word)){
			wordCount.set(word,wordCount.get(word)+1);
		}
		else{
			wordCount.set(word,1);
		}
	}
	for(let [key,value] of wordCount){
		console.log(`${key} ${value}`);
	}
}();
g.next();

#Python
words=(input()
		.strip()
		.split(" "))
wordCount=dict();
for word in words:
	if word in wordCount:
		wordCount[word]+=1
	else:
		wordCount[word]=1

for key,value in wordCount.items():
	print(f"{key} {value}")