結果

問題 No.327 アルファベット列
ユーザー naimonon77
提出日時 2016-09-22 14:39:19
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,763 bytes
コンパイル時間 1,672 ms
コンパイル使用メモリ 172,948 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-17 13:08:15
合計ジャッジ時間 3,039 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#define REP(i,a,b) for(i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define ALL(a) begin(a),end(a)
#define ifnot(a) if(not a)
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

// #define int ll
#ifdef _MSC_VER
bool test = true;
#else 
bool test = false;
#endif

int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define INF (1 << 28)
ull mod = (int)1e9 + 7;
//.....................
#define MAX (int)1e6 + 5

template<class T>
T pow(T x, T n) {
	T res = 1;
	while (n > 0) {
		if (n & 1) res = res * x;
		x = x * x;
		n >>= 1;
	}
	return res;
}

string mode0(ll N) {
	int i;
	string s = "A";
	rep(i, N) {
		int now = 0;
		while (1) {
			if (now == s.size()) {
				s.push_back('A');
				break;
			}
			else if (s[now] == 'Z') {
				s[now] = 'A';
				now++;
			}
			else {
				s[now]++;
				break;
			}
		}
	}
	reverse(ALL(s));
	return s;
}

const ll alphabet_num = 26;

string mode1(ll N) {
	int i;
	vector<ll> v;
	ll now = N;
	v.push_back(now % 26);
	now /= 26;
	REP(i, 1, 100) {
		if (now == 0) break;
		ll value = now % 26 - 1;
		if (value < 0) {
			now -= 26;
			value += 26;
		}
		v.push_back(value);
		now /= 26;
	}

	string s;
	for (i = v.size() - 1; i > -1; i--) {
		s.push_back((char)(v[i] + 'A'));
	}
	return s;

	//ll sum = 0;
	//while (1) {
	//	if (N < sum) break;
	//	sum += pow((ll)26,now+1);
	//}
}

signed main(void) {
	int i, j, k, l;
	int mode = 1;
	function<string(ll)> f[] = { mode0,mode1 };
	string s;
	while (cin >> s) {
		if (isdigit(s[0])) {
			cout << f[mode](stoll(s)) << endl;
		}
		else if (s == "mode0") mode = 0;
		else if (s == "mode1") mode = 1;
	}
	return 0;
}
0