博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
decimal system 2016
阅读量:7079 次
发布时间:2019-06-28

本文共 2418 字,大约阅读时间需要 8 分钟。

Problem Description
As we know , we always use the decimal system in our common life, even using the computer. If we want to calculate the value that 3 plus 9, we just import 3 and 9.after calculation of computer, we will get the result of 12.
But after learning <<The Principle Of Computer>>,we know that the computer will do the calculation as the following steps:
1 computer change the 3 into binary formality like 11;
2 computer change the 9 into binary formality like 1001;
3 computer plus the two number and get the result 1100;
4 computer change the result into decimal formality like 12;
5 computer export the result;
In the computer system there are other formalities to deal with the number such as hexadecimal. Now I will give several number with a kind of change method, for example, if I give you 1011(2), it means 1011 is a number in the binary system, and 123(10) means 123 if a number in the decimal system. Now I will give you some numbers with any kind of system, you guys should tell me the sum of the number in the decimal system.
 

 

Input
There will be several cases. The first line of each case contains one integers N, and N means there will be N numbers to import, then there will be N numbers at the next N lines, each line contains a number with such form : X1….Xn.(Y), and 0<=Xi<Y, 1<Y<=10. I promise you that the sum will not exceed the 100000000, and there will be at most 100 cases and the 0<N<=1000.
 

 

Output
There is only one line output case for each input case, which is the sum of all the number. The sum must be expressed using the decimal system.
 

 

Sample Input
3 1(2) 2(3) 3(4) 4 11(10) 11(2) 11(3) 11(4)
 

 

Sample Output
6 23

 

 

 

 

 

1 #include 
2 using namespace std; 3 4 int pow(int m,int n)//求m的n次幂 5 { 6 long int pro = 1; 7 while(n--) 8 pro *= m; 9 return pro; 10 } 11 12 int main() 13 { 14 int T,p,q;//k为指数 15 16 char left_arc,right_arc; 17 while (cin >> T) 18 { 19 int sum = 0; 20 while(T--) 21 { 22 int k = 0; 23 cin >> p >> left_arc >> q >> right_arc; 24 25 while (p != 0) 26 { 27 sum += p % 10 * pow(q,k++); 28 p /= 10; 29 } 30 } 31 cout << sum << endl; 32 } 33 34 return 0; 35 }

 

转载于:https://www.cnblogs.com/wangmengmeng/p/4655250.html

你可能感兴趣的文章
[转] MySQL死锁问题分析及解决方法实例详解
查看>>
React Native CodePush实践小结
查看>>
怎么才算是高级工程师?
查看>>
JavaScript学习笔记 - 基本概念
查看>>
Angular 2 Change Detection - 1
查看>>
ReactJS新闻 #19 React Conf 2017将于3/13开始
查看>>
CI-CodeIgniter中“超级对象”:$CI =& get_instance()
查看>>
设计模式之单例模式
查看>>
Scrapy学习(四) 爬取微博数据
查看>>
LinkedIn庄振运:从国家部委公务员到硅谷系统性能专家,创新是唯一主旋律
查看>>
Vue性能优化:如何实现延迟加载和代码拆分?
查看>>
小米大数据:借助Apache Kylin打造高效、易用的一站式OLAP解决方案
查看>>
2019年Java和JVM生态系统预测:OpenJDK将成为Java运行时市场领导者
查看>>
Peter Cnudde谈雅虎如何使用Hadoop、深度学习和大数据平台
查看>>
Spark Streaming 作者,Alluxio 的创始人李浩源:AI 潮流对做数据存储业务公司的挑战...
查看>>
阿里宣布开源Flutter应用框架Fish Redux!
查看>>
与Andrey Breslav谈论Kotlin 1.0的发布
查看>>
多链跨链、高可用、高安全性的区块链应用如何落地? 金链盟大赛10强揭晓
查看>>
京东购物在微信等场景下的算法应用实践
查看>>
取代ZooKeeper!高并发下的分布式一致性开源组件StateSynchronizer
查看>>