Untitled
unknown
c_cpp
4 years ago
1.4 kB
5
Indexable
#include <iostream>
#include <set>
#include <sstream>
#include <string>
std::string solution(std::string& S)
{
std::istringstream ist(S);
std::string tmp;
std::set<std::string> music_set{ ".mp3", ".vaw" },
img_set{ ".jpg", ".png" }, mov_set{ ".mp4", ".avi" };
int count = 1, music = 0, img = 0, mov = 0, etc = 0;
int* it;
while (ist >> tmp)
{
if (count % 2)
{
std::string format_fille = tmp.substr(
tmp.find_last_of('.', tmp.size() - 1), tmp.size() - 1);
if (music_set.find(format_fille) != music_set.end())
{
it = &music;
}
else if (img_set.find(format_fille) != img_set.end())
{
it = &img;
}
else if (mov_set.find(format_fille) != mov_set.end())
{
it = &mov;
}
else
{
it = &etc;
}
}
else
{
tmp.pop_back();
int N = stoi(tmp);
*it += N;
}
++count;
}
std::string result;
result = "music " + std::to_string(music) + "b\n" + "img " +
std::to_string(img) + "b\n" + "mov " + std::to_string(mov) +
"b\n" + "etc " + std::to_string(etc) + "b\n";
return result;
}
Editor is loading...