PAT (Advanced Level)1019. General Palindromic Number (20) 栈 进制转换(简)
2018-03-01 16:39
621 查看
题目链接
和115题类型相同,简单题//1019. General Palindromic Number(20)
#include <iostream>
#include <stack>
using namespace std;
int main() {
int a, b, i;
stack<int> st;
cin >> a >> b;
int c[15];
int sub = 0;
while (a != 0) {
c[sub++] = a % b;
a /= b;
}
for (i = 0; i < sub / 2; i++) st.push(c[i]);
if (sub % 2 != 0) i++;
for (i; i < sub; i++) if (st.top() == c[i]) { st.pop(); continue; }
else break;
if (i >= sub) {
cout << "Yes" << endl;
cout << c[sub - 1];
for (i = sub - 2; i >= 0; i--) cout << " " << c[i];
cout << endl;
}
else {
cout << "No" << endl;
cout << c[sub - 1];
for (i = sub - 2; i >= 0; i--) cout << " " << c[i];
cout << endl;
}
return 0;
}
和115题类型相同,简单题//1019. General Palindromic Number(20)
#include <iostream>
#include <stack>
using namespace std;
int main() {
int a, b, i;
stack<int> st;
cin >> a >> b;
int c[15];
int sub = 0;
while (a != 0) {
c[sub++] = a % b;
a /= b;
}
for (i = 0; i < sub / 2; i++) st.push(c[i]);
if (sub % 2 != 0) i++;
for (i; i < sub; i++) if (st.top() == c[i]) { st.pop(); continue; }
else break;
if (i >= sub) {
cout << "Yes" << endl;
cout << c[sub - 1];
for (i = sub - 2; i >= 0; i--) cout << " " << c[i];
cout << endl;
}
else {
cout << "No" << endl;
cout << c[sub - 1];
for (i = sub - 2; i >= 0; i--) cout << " " << c[i];
cout << endl;
}
return 0;
}
相关文章推荐
- 【c++】PAT (Advanced Level)1019. General Palindromic Number (20)
- PAT (Advanced Level) Practise 1019. General Palindromic Number (20)
- 1019. General Palindromic Number (20) @ PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise 1019 General Palindromic Number (20)
- PAT (Advanced Level) 1019. General Palindromic Number (20) 检测数字在给定进制下是否回文
- 【PAT Advanced Level】1019. General Palindromic Number (20)
- PAT (Advanced Level) Practise 1019 General Palindromic Number (20)
- 1019. General Palindromic Number (20)——PAT (Advanced Level) Practise
- 浙大 PAT Advanced level 1019. General Palindromic Number (20)
- PAT (Advanced Level) Practise 1019. General Palindromic Number (20)
- PAT (Advanced Level) 1019. General Palindromic Number (20)
- 【PAT】【Advanced Level】1019. General Palindromic Number (20)
- Pat(Advanced Level)Practice--1019(General Palindromic Number)
- PAT(Advanced Level) 1019 - General Palindromic Number(水题)
- PAT (Advanced) 1019. General Palindromic Number (20)
- 【PAT】1019. General Palindromic Number (20)
- PAT 1019. General Palindromic Number (20)
- PAT甲级真题及训练集(12)--1019. General Palindromic Number (20)
- 【PAT甲级】1019. General Palindromic Number (20)
- 浙大 PAT 1019. General Palindromic Number (20)