首页 > 学院 > 开发设计 > 正文

1019. General Palindromic Number (20)

2019-11-14 09:34:56
字体:
来源:转载
供稿:网友

题目不难,用vector存储转换进制的各个位,然后转置一下,进行比较,相等即Yes

#include<iostream>#include<vector>using namespace std;int main(){ int N;; int b; cin >> N >> b; char c; vector<int> vec1,vec2; while (N / b != 0) { vec1.push_back(N%b); N = N / b; } vec1.push_back(N); for (auto it = vec1.rbegin();it != vec1.rend();it++)//转置 vec2.push_back(*it); if (vec1 == vec2) cout << "Yes" << endl<<vec2[0];//判断 else cout << "No" << endl<<vec2[0]; for (unsigned int t = 1;t < vec2.size();t++) cout << " " << vec2[t]; cout << endl;}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表