結果

問題 No.164 ちっちゃくないよ!!
ユーザー furafyfurafy
提出日時 2015-07-30 03:56:49
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,666 bytes
コンパイル時間 623 ms
コンパイル使用メモリ 76,432 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-24 22:11:44
合計ジャッジ時間 1,332 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 2 ms
4,380 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <string>
#include <cstring>

using namespace std;

char getBiggestChar(vector<string> &V) {
	char ret = V[0][0];
	for (int i = 0; i < V.size(); i++) {
		string s = V[i];
		for (int j = 0; j < s.size(); j++) {
			if (s[j] > ret) {
				ret = s[j];
			}
		}
	}
	return ret;
}

bool isNumber(char c) {
	return c <= 57;
}

int toNumber(char c) {
	int ret = (int)c;
	if (isNumber(c)) {
		ret -= 48;
	} else {
		ret -= 55;
	}
	return ret;
}

int toBase(char c) {
	return toNumber(c) + 1;
}

int getMinIndex(vector<string> &V) {
	int mindex = 0;
	int min = V[0].size();
	for (int i = 0; i < V.size(); i++) {
		string s = V[i];
		int j = 0;
		while (V[i][j] == '0') {
			j++;
		}
		int len = 0;
		while (j < s.size()) {
			j++;
			len++;
		}
		if (len < min) {
			min = len;
			mindex = i;
		} else if (len == min) {
			for (int l = 0; l < s.size(); l++) {
				if (V[i][l] > V[mindex][l]) {
					min = len;
					mindex = i;
					break;
				}
			}
		}
	}
	return mindex;
}

int encode(string s, int b) {
	long long ret = 0;
	for (int i = 0; i < s.size(); i++) {
		int num = toNumber(s[s.size() - 1 - i]);
		ret += pow(b, i) * num;
	}
	return ret;
}

int main(void) {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int N;
	cin >> N;
	vector<string> V;
	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		V.push_back(s);
	}
	int base = toBase(getBiggestChar(V));
	int mindex = getMinIndex(V);
	cout << encode(V[mindex], base) << endl;
}
0