[プログラマー]ハッシュ-偽装
質問リンク
質問する
質問する
に答える
服装の名前と服装の種類はペアです.
これは種類数で組み合わせた問題です.
上のI/O#1を見ると
服の種類.
headger->yellow hat,green turban->2種
めがね
可能な服の組み合わせ.
headger->yellow hat,green turban,選択しない->3種類
眼鏡->ブルーサングラス、選択しない->2種類
3*2=6
何も選択しない場合はないので、1つを除いて5種類の組み合わせが選べます.
従って、mapにkey(衣類の種類)value(種類数)で格納し、状況の数を算出することができる.
コード#コード# #include <string>
#include <vector>
#include <iostream>
#include <unordered_map>
using namespace std;
int solution(vector<vector<string>> clothes) {
int answer = 1;
unordered_map<string, int> category;
// map에 옷 가짓수 저장
for(int i=0;i<clothes.size();i++){
category[clothes[i][1]] ++;
}
for(auto pair:category){
answer *= pair.second+1;
}
answer--;
return answer;
}
int main(){
vector<vector<string>> clothes =
{{"yellowhat", "headgear"},
{"bluesunglasses", "eyewear"},
{"green_turban", "headgear"}};
solution(clothes);
return 0;
}
Reference
この問題について([プログラマー]ハッシュ-偽装), 我々は、より多くの情報をここで見つけました
https://velog.io/@peanut_/프로그래머스-해시-위장
テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol
服装の名前と服装の種類はペアです.
これは種類数で組み合わせた問題です.
上のI/O#1を見ると
服の種類.
headger->yellow hat,green turban->2種
めがね
可能な服の組み合わせ.
headger->yellow hat,green turban,選択しない->3種類
眼鏡->ブルーサングラス、選択しない->2種類
3*2=6
何も選択しない場合はないので、1つを除いて5種類の組み合わせが選べます.
従って、mapにkey(衣類の種類)value(種類数)で格納し、状況の数を算出することができる.
コード#コード# #include <string>
#include <vector>
#include <iostream>
#include <unordered_map>
using namespace std;
int solution(vector<vector<string>> clothes) {
int answer = 1;
unordered_map<string, int> category;
// map에 옷 가짓수 저장
for(int i=0;i<clothes.size();i++){
category[clothes[i][1]] ++;
}
for(auto pair:category){
answer *= pair.second+1;
}
answer--;
return answer;
}
int main(){
vector<vector<string>> clothes =
{{"yellowhat", "headgear"},
{"bluesunglasses", "eyewear"},
{"green_turban", "headgear"}};
solution(clothes);
return 0;
}
Reference
この問題について([プログラマー]ハッシュ-偽装), 我々は、より多くの情報をここで見つけました
https://velog.io/@peanut_/프로그래머스-해시-위장
テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol
#include <string>
#include <vector>
#include <iostream>
#include <unordered_map>
using namespace std;
int solution(vector<vector<string>> clothes) {
int answer = 1;
unordered_map<string, int> category;
// map에 옷 가짓수 저장
for(int i=0;i<clothes.size();i++){
category[clothes[i][1]] ++;
}
for(auto pair:category){
answer *= pair.second+1;
}
answer--;
return answer;
}
int main(){
vector<vector<string>> clothes =
{{"yellowhat", "headgear"},
{"bluesunglasses", "eyewear"},
{"green_turban", "headgear"}};
solution(clothes);
return 0;
}
Reference
この問題について([プログラマー]ハッシュ-偽装), 我々は、より多くの情報をここで見つけました https://velog.io/@peanut_/프로그래머스-해시-위장テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol