PAT 天梯赛 L1-050. 倒数第N个字符串 【字符串】
2018-04-01 14:17
411 查看
题目链接
https://www.patest.cn/contests/gplt/L1-050
思路
因为是求倒数 我们不如直接 倒过来看 令 zzz 为第一个字符串
我们可以理解为 十进制 转换为 二十六进制
我们分别令
z, y, x …… a 为 25 , 24 , 23 ……….. 0
然后我们知道 第一个字符串 zzz 代表的数字是 0 但是它是第一个字符串
所以 这里 是相差一位的 我们不如直接 将 zzz 表示为 第0个字符串 那么给的N 就要相应的 - 1
然后进制转换 用字母来表示 就可以了
AC代码
https://www.patest.cn/contests/gplt/L1-050
思路
因为是求倒数 我们不如直接 倒过来看 令 zzz 为第一个字符串
我们可以理解为 十进制 转换为 二十六进制
我们分别令
z, y, x …… a 为 25 , 24 , 23 ……….. 0
然后我们知道 第一个字符串 zzz 代表的数字是 0 但是它是第一个字符串
所以 这里 是相差一位的 我们不如直接 将 zzz 表示为 第0个字符串 那么给的N 就要相应的 - 1
然后进制转换 用字母来表示 就可以了
AC代码
#include <cstdio> #include <cstring> #include <ctype.h> #include <cstdlib> #include <cmath> #include <climits> #include <ctime> #include <iostream> #include <algorithm> #include <deque> #include <vector> #include <queue> #include <string> #include <map> #include <stack> #include <set> #include <numeric> #include <sstream> #include <iomanip> #include <limits> #define CLR(a) memset(a, 0, sizeof(a)) #define pb push_back using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair <int, int> pii; typedef pair <ll, ll> pll; const double PI = 3.14159265358979323846264338327; const double E = exp(1); const double eps = 1e-6; const int INF = 0x3f3f3f3f; const int maxn = 1e5 + 5; const int MOD = 1e9 + 7; int main() { map <int, char> m; for (int i = 'z', j = 0; i >= 'a'; i--, j++) m[j] = i; int a, b; scanf("%d%d", &a, &b); b--; int ans[6]; CLR(ans); for (int i = 0; b; i++) { ans[i] = b % 26; b /= 26; } string s = ""; for (int i = 0; i < a; i++) s += m[ans[i]]; reverse(s.begin(), s.end()); cout << s << endl; }
相关文章推荐
- PAT - 天梯赛 L1-050 倒数第N个字符串
- PAT L1-050. 倒数第N个字符串
- 【PAT】L1-050. 倒数第N个字符串【C语言实现】
- L1-050. 倒数第N个字符串
- PAT-2018 L1-050. 倒数第N个字符串
- L1-050. 倒数第N个字符串
- C++:L1-050. 倒数第N个字符串
- L1-050. 倒数第N个字符串
- L1-050. 倒数第N个字符串
- PAT 团体程序设计天梯赛 倒数第N个字符串
- PAT 天梯赛 L1-032. Left-pad 【字符串】
- L1-050. 倒数第N个字符串 天梯赛
- PAT 天梯赛 L1-027. 出租 (简单字符串处理)
- PAT 天梯赛 L1-054. 福到了 【字符串】
- PAT L1 050 倒数第N个字符串 (递归/模拟)
- 天梯赛 倒数第n个字符串
- PAT 天梯赛 L1-039. 古风排版 【字符串处理】
- PAT 天梯赛 L1-025. 正整数A+B 【字符串处理】
- L1-2 倒数第N个字符串
- PAT 天梯赛 L1-002 【递归】