Artifact Content
Not logged in

Artifact b5579a44800aff387c583179d047c1a0472bbccd


#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef complex<LD> CMP;

class FoxAndMp3 { public:
	set<int> used;
	vector <string> playList(int n)
	{
		vector<string> answer;
		int v = 1;
		while(answer.size() <= 50)
		{
			used.insert(v);
			answer.push_back(to_s(v)+".mp3");
			int vv;
			if(!next(v,n,&vv))
				break;
			v=vv;
			if(v==0)
				break;
		}
		return answer;
	}

	string to_s(int v)
	{
		stringstream ss;
		ss << v;
		return ss.str();
	}

	bool next(int v, int n, int* vv)
	{
		if(v*10<=n) {
			*vv = v*10;
			return true;
		}
		if(v+1 <= n && (v+1)%10!=0) {
			*vv = v+1;
			return true;
		}
		if(v+1 > n || (v+1)%10==0) {
			*vv=v/10+1;
			return !used.count(*vv);
		}
		return false;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const vector <string>& Expected, const vector <string>& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: " << Expected << endl << "\tx: " << Received << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, FoxAndMp3().playList(n));}
int main(){

CASE(0)
	int n = 3; 
	string __[] = {"1.mp3", "2.mp3", "3.mp3" };
	  vector <string> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(1)
	int n = 10; 
	string __[] = {"1.mp3", "10.mp3", "2.mp3", "3.mp3", "4.mp3", "5.mp3", "6.mp3", "7.mp3", "8.mp3", "9.mp3" };
	  vector <string> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(2)
	int n = 16; 
	string __[] = {"1.mp3", "10.mp3", "11.mp3", "12.mp3", "13.mp3", "14.mp3", "15.mp3", "16.mp3", "2.mp3", "3.mp3", "4.mp3", "5.mp3", "6.mp3", "7.mp3", "8.mp3", "9.mp3" };
	  vector <string> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(3)
	int n = 32; 
	string __[] = {"1.mp3", "10.mp3", "11.mp3", "12.mp3", "13.mp3", "14.mp3", "15.mp3", "16.mp3", "17.mp3", "18.mp3", "19.mp3", "2.mp3", "20.mp3", "21.mp3", "22.mp3", "23.mp3", "24.mp3", "25.mp3", "26.mp3", "27.mp3", "28.mp3", "29.mp3", "3.mp3", "30.mp3", "31.mp3", "32.mp3", "4.mp3", "5.mp3", "6.mp3", "7.mp3", "8.mp3", "9.mp3" };
	  vector <string> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(4)
	int n = 100000009; 
	string __[] = {"1.mp3", "10.mp3", "100.mp3", "1000.mp3", "10000.mp3", "100000.mp3", "1000000.mp3", "10000000.mp3", "100000000.mp3", "100000001.mp3", "100000002.mp3", "100000003.mp3", "100000004.mp3", "100000005.mp3", "100000006.mp3", "100000007.mp3", "100000008.mp3", "100000009.mp3", "10000001.mp3", "10000002.mp3", "10000003.mp3", "10000004.mp3", "10000005.mp3", "10000006.mp3", "10000007.mp3", "10000008.mp3", "10000009.mp3", "1000001.mp3", "10000010.mp3", "10000011.mp3", "10000012.mp3", "10000013.mp3", "10000014.mp3", "10000015.mp3", "10000016.mp3", "10000017.mp3", "10000018.mp3", "10000019.mp3", "1000002.mp3", "10000020.mp3", "10000021.mp3", "10000022.mp3", "10000023.mp3", "10000024.mp3", "10000025.mp3", "10000026.mp3", "10000027.mp3", "10000028.mp3", "10000029.mp3", "1000003.mp3" };
	  vector <string> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(5)
	int n = 1; 
	string __[] = {"1.mp3" };
	  vector <string> _(__, __+sizeof(__)/sizeof(*__)); 
END
/*
CASE(6)
	int n = ; 
	string __[] = ;
	  vector <string> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(7)
	int n = ; 
	string __[] = ;
	  vector <string> _(__, __+sizeof(__)/sizeof(*__)); 
END
*/
}
// END CUT HERE