Skip to content

Instantly share code, notes, and snippets.

@plasma-effect
Created April 2, 2015 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plasma-effect/22992257fdf643b5eeae to your computer and use it in GitHub Desktop.
Save plasma-effect/22992257fdf643b5eeae to your computer and use it in GitHub Desktop.
//The MIT License(MIT)
//
//Copyright(c) 2015 plasma-effect
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files(the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions :
//
//The above copyright notice and this permission notice shall be included in
//all copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//THE SOFTWARE.
#include<iostream>
#include<fstream>
#include<vector>
#include<string>
#include<array>
#include<boost/lexical_cast.hpp>
const char filename[] = "pokemon_id_data.txt";
std::vector<int> load()
{
std::fstream fs(filename);
if (!fs)
return std::vector<int>();
std::string str;
std::vector<int> vec;
while (std::getline(fs, str))
{
auto n = boost::lexical_cast<std::size_t>(str);
if (n < 100000)
vec.push_back(n);
}
return vec;
}
void save(std::vector<int> const& vec)
{
std::ofstream fs(filename, std::ios::trunc);
for (auto n : vec)
{
fs << n << std::endl;
}
}
int main()
{
auto vec = load();
std::string str;
while (true)
{
std::cin >> str;
if (str == "exist")
{
save(vec);
break;
}
else if (str == "check")
{
std::array<bool, 100> flag;
for (auto& f : flag)
{
f = false;
}
for (auto n : vec)
{
flag[n % 100] = true;
}
std::cout << "まだ持ってないのは" << std::endl;
for (int i = 0; i < 100; ++i)
{
if (!flag[i])
std::cout << i << std::endl;
}
std::cout << "ここまで" << std::endl;
}
else
{
auto n = boost::lexical_cast<std::size_t>(str);
if (n < 100000)
vec.push_back(n);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment