codeforces 13a(进制转换)
来源:互联网 发布:武汉软件行业区域 编辑:程序博客网 时间:2024/05/21 10:21
通过这道题引入一下十进制转化为任意进制数的模板。
题解:
#include <iostream>using namespace std;int gcd(int a,int b){return b==0 ? a : gcd(b,a%b);}int main() { int n; int p,c;int s[100]; int sum=0,count=0; int i,j; cin>>n; int x,y;for(i=2;i<n;i++){x=n;p=i;while (x!=0) { c=x%p; x=x/p; s[count++]=c; } for(j=0;j<count;j++){ sum+=s[j];} count=0;}y=gcd(sum,n-2);cout<<sum/y<<"/"<<(n-2)/y<<endl; return 0;}
模板:
#include <iostream>using namespace std;int main() { int n,p; int dig,count=0; int s[100]; cin>>n; //要转化的数字 cin>>p; //要转换的进制 //数制转换 while (n!=0) { dig=n%p; n=n/p; s[count++]=dig; }//输出转换后的序列 for(int k=count-1; k>=0; k--) { if(s[k]>=10) cout<<(char)(s[k]+55); else cout<<s[k]; } return 0;}
阅读全文
0 0
- codeforces 13a(进制转换)
- Codeforces Round #333 (Div. 2) A. Two Bases (进制转换比较大小)
- CodeForces 131A--大小写转换
- codeforces 1B Spreadsheets(26进制转换)
- codeforces 13A. Numbers
- CodeForces 13A
- CodeForces 13A - Numbers
- CodeForces-13A-Numbers
- CodeForces 13A【暴力】
- CodeForces 13A Numbers
- HDU 1877 又一版 A+B(进制转换)
- hdu 1720 A+B Coming (进制转换)
- HDU 3787 A+B(字符串进制转换)
- 火星A+B (进制转换变形)
- PAT-1058 A+B in Hogwarts (进制转换)
- cf 602 A(进制转换)
- A题 序号互换(进制转换)
- Codeforces 202(DIV2)A
- JAVA的四种访问修饰符
- 更新github项目上的代码
- Android--广播发送者及广播接收者
- 迷茫
- Python函数篇(3)-内置函数、文件处理
- codeforces 13a(进制转换)
- 创建序列及修改序列
- BIGEMAP功能
- 通过HttpURLConnection 上传文件
- linux 下jdk的安装与配置
- iOS 获取手机通讯录常用的两种方式
- android Studiod的快捷键
- Http请求中Content-Type讲解以及在Spring MVC中的应用
- Oracle 数值函数和日期函数总结