base

Recursive function to convert between number bases fails at certain numbers

故事扮演 提交于 2019-12-24 10:44:02
问题 I'm trying to a create an algorithm that can convert base 10 numbers into base n numbers, where n is at most 10. However, for some weird reason the following algorithm in C fails at certain critical points for each base. For example, for base 2 and base 3 conversions, all numbers up to and including 1023 and 52,487 work, respectively, but numbers beyond that produce some weird negative result. I can't figure out why this is happening; can anyone help me? #include <stdio.h> #include <stdlib.h>

How to calculate as quick as possible the base 3 value of an integer which is given as a huge sequence of decimal digits (more than one million)?

青春壹個敷衍的年華 提交于 2019-12-24 10:30:03
问题 We got this task from our professor. Prerequisites are: Use Python 3 and use only build-in functions (no numpy). Main task: Find and store the result within 5 sec. Minor task, just nice to have: Find not only the value for base b=3, but also for the bases b=3**k (with k = 2,3,4). Compared to our 1st straight-forward solution, we achieved an improvement by factor 96 (almost 100 times faster), but still it doesn't fulfill the 5 sec limit (currently, we are at 25 sec on an i7 laptop). [Our prof

Base href not working on IE - alternative?

会有一股神秘感。 提交于 2019-12-24 03:18:17
问题 So after doing a lot of research I found base href, and I decided I should use it to build my website. After finishing I noticed that it was working on every browser(latest version): Chrome/Firefox/Opera except IE 9. My site is built like that, on localhost: <base href="/My_Site/" /> Then I use php include to add elements found on root directory and not in the same folder with current page: <?php include "../header.php"?> Now since I will be uploading this to the web, I suppose base href will

number base conversion in .htaccess

允我心安 提交于 2019-12-23 12:33:51
问题 I intend to do a url redirection of the form : from: domain.com/A into domain.com/someResourse/id/10 in this redirection the base of the id is changed from 16 to 10 . I wonder if this is possible using .htaccess 回答1: You could use RewriteMap with the external program mapping (prg:). This is a quite adavnced use of mod-rewrite and even of RewriteMap. RewriteLock /var/lock/rewritemaplock.lock RewriteMap base16to10 prg:/somewher/modrewritemapbase16to10.pl RewriteRule - ${base16to10:%{REQUEST_URI

Converting base 6 to decimal and vice versa in Python? [closed]

谁说我不能喝 提交于 2019-12-23 06:26:13
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 years ago . I'm trying to convert a number from decimal to base 6 and vice versa, but it's not working. It seems that I'm not figuring out the algorithm to get it to work. Could someone please explain to me how to implement it in Python? Here is a link(Click here) which gives an explanation on how to do it,

题解 P1017 【进制转换】

假如想象 提交于 2019-12-23 05:51:19
我赶jio这个题难道是让我们写快写? 不管了,赶紧把咕咕咕了一万年的题解写出来。 这个题就是考察负进制和 在mod意义下的除法运算的基础运算 。 (其实也没多大问题) 首先我们先假设一个原始数据 \(num\) 和基底 \(base(1\leq base\leq20)\) 然后不妨设 \(num=a*base+b\) (且$b = num\space mod\space a $ ) 重点来了! 如果 \(b<0\) ,我们就 \(b-base,a+1\) ,很明显这样做是正确的。 为啥呢?因为base是负数。负数减去一个比第一个负数大的负数肯定是个正数,而且不影响后面的数字的拆开。 (恒等变换自己拆开式子便知道了) 我们其实只需要 \(b\) 这一个数据,让 \(a*base\) 留在原来剩下的num中继续递归就可以。 最后一个 坑 : 窝一开始设的 char[]="0123456789ABCDEF" ,有两个错误: 没有'G' 输出基本是空的(我也不知道为啥 不管了放个cpp #include <iostream> #include <cstdio> #include <stack> #include <string> using namespace std; //用了string类型再错就去世 string str="0123456789ABCDEFG"; string

How to call virtual function of derived class through base class pointer

早过忘川 提交于 2019-12-22 05:59:27
问题 Let's see this code: class CBase { public: virtual vfunc() { cout << "CBase::vfunc()" << endl; } }; class CChild: public CBase { public: vfunc() { cout << "CChild::vfunc()" << endl; } }; int main() { CBase *pBase = new CBase; ((CChild*)pBase)->vfunc(); // !!! important delete pBase; return 0; } The output is: CBase::vfunc() But I want to see: CChild::vfunc() Explicit ((CChild*)pBase) casts to type "CChild*". So why to call derived vfunc() I need replace "important" string with: ((CChild*

C++继承

半世苍凉 提交于 2019-12-22 00:14:01
  C++继承可以是单一继承或多重继承,每一个继承连接可以是public,protected,private也可以是virtual或non-virtual。然后是各个成员函数选项可以是virtual或non-virtual或pure virtual。本文仅仅作出一些关键点的验证。   public继承,例如下: 1 class base 2 {...} 3 class derived:public base 4 {...}   如果这样写, 编译器会理解成类型为derived的对象同时也是类型为base的对象,但类型为base的对象不是类型为derived的对象。这点很重要。 那么函数形参为base类型适用于derived,形参为derived不适用于base。下面是验证代码,一个参数为base的函数,传入derived应该成功执行,相反,一个参数为derived的函数 1 #include <iostream> 2 #include <stdio.h> 3 4 class base 5 { 6 public: 7 base() 8 :baseName(""),baseData(0) 9 {} 10 11 base(std::string bn,int bd) 12 :baseName(bn),baseData(bd) 13 {} 14 15 std::string

17、字符串转换整数 (atoi)

岁酱吖の 提交于 2019-12-21 08:12:11
17、字符串转换整数 (atoi) 请你来实现一个 atoi 函数,使其能将字符串转换成整数。 首先,该函数会根据需要丢弃无用的开头空格字符,直到寻找到第一个非空格的字符为止。 当我们寻找到的第一个非空字符为正或者负号时,则将该符号与之后面尽可能多的连续数字组合起来,作为该整数的正负号;假如第一个非空字符是数字,则直接将其与之后连续的数字字符组合起来,形成整数。 该字符串除了有效的整数部分之后也可能会存在多余的字符,这些字符可以被忽略,它们对于函数不应该造成影响。 注意:假如该字符串中的第一个非空格字符不是一个有效整数字符、字符串为空或字符串仅包含空白字符时,则你的函数不需要进行转换。 在任何情况下,若函数不能进行有效的转换时,请返回 0。 说明: 假设我们的环境只能存储 32 位大小的有符号整数,那么其数值范围为 [−231, 231 − 1]。如果数值超过这个范围,qing返回 INT_MAX (231 − 1) 或 INT_MIN (−231) 。 示例 1: 输入: "42" 输出: 42 示例 2: 输入: " -42" 输出: -42 解释: 第一个非空白字符为 '-', 它是一个负号。 我们尽可能将负号与后面所有连续出现的数字组合起来,最后得到 -42 。 示例 3: 输入: "4193 with words" 输出: 4193 解释: 转换截止于数字 '3'

从ACID到CAP到BASE

百般思念 提交于 2019-12-20 20:30:57
学习思路 CAP理论 BASE理论 应用场景 ACID相关请看《 ACID-本地事务-分布式事务 》 一、CAP理论 C(一致性):分布式系统中所有备份节点的数据任何时间都保持一致(从任何一个节点取到的数据都一样) A(可用性):系统在任何情况下(发生故障)都仍然可以对外提供服务(高可用) P(分区容错性):如果数据产生了不一致的情况或者始终高可用,那么肯定存在分区(我们所有的线上服务都是集群部署) 一致性和可用性是我们设计的目标,但就目前的系统设计来说分区容错性又是不可避免的,下面我们单独分析CA、CP、AP CA:放弃分区容错意味着是单机服务,宕机概率大,一旦宕机后整个服务不可用(线上避免) CP:放弃可用性,保证数据一致性和分区容错,意味着我们在做数据同步(一致性)的时候系统可能一直处于等待,直至所有数据一致(比如我们之前说的分布式事务2PC、3PC) AP:放弃一致性,意味着数据在短时间内可能是不一致的,但一直能对外服务 就现阶段的微服务架构设计中CA很明显不符合,因此我们将在CP和AP中根据不同场景分别设计 我们比较熟悉的zookeeper是CP系统,eureka是AP系统 这里联想到为什么eureka比zookeeper更适合做注册中心:eureka是去中心化设计,每个节点都可以单独对外读写,数据同步可能出现短暂时间差,但zk是leader负责写并同步其它节点