base

查找无限整数序列的第n位1,2,3,4,5,6,7,8,9,10,11,...

我怕爱的太早我们不能终老 提交于 2019-12-04 16:02:14
思路: 1.1-9 有9 位数,10-99 有180 位。因此我们首先找到这个位数是几位数。 2.在找到这个数, 3.确定这个数的第几位是我们要找的。 代码: public class FindNthDigit { public static int findNthDigitSolution(int n){ // 1. 计算这个数是几位数 int digits = 1; // 几位数 int base = 1; int count = 9*base*digits; while(n-count>0){ digits++; n -= count; base *= 10; count = 9*base*digits; } // 2.计算这个数是几 int index = n%digits; // target 位于这个数的第几位 if(index == 0){ index = digits; // 能整除,说明在 digits 位 } int num = base+(index == digits ? n/digits-1:n/digits); // 3.计算这个数的 index 位是几 while(index<digits){ num /= 10; index++; } return num%10; // 经验证可知,n==0时,这样的逻辑能返回正确结果0。 } public

Specify different types of missing values (NAs)

倾然丶 夕夏残阳落幕 提交于 2019-12-04 10:24:39
问题 I'm interested to specify types of missing values. I have data that have different types of missing and I am trying to code these values as missing in R, but I am looking for a solution were I can still distinguish between them. Say I have some data that looks like this, set.seed(667) df <- data.frame(a = sample(c("Don't know/Not sure","Unknown","Refused","Blue", "Red", "Green"), 20, rep=TRUE), b = sample(c(1, 2, 3, 77, 88, 99), 10, rep=TRUE), f = round(rnorm(n=10, mean=.90, sd=.08), digits =

Base class undefined

若如初见. 提交于 2019-12-04 04:41:32
My code below generates the error 'WorldObject': [Base class undefined (translated from german)] Why is this? Here is the code which produces this error: ProjectilObject.h: #pragma once #ifndef _PROJECTILOBJECT_H_ #define _PROJECTILOBJECT_H_ #include "GameObjects.h" class WorldObject; class ProjectilObject: public WorldObject { public: ProjectilObject(IGameObject* parent,int projectiltype); void deleteyourself(); protected: virtual void VProcEvent( long hashvalue, std::stringstream &stream); virtual void VInit(); virtual void VInitfromStream( std::stringstream &stream ); virtual void VonUpdate

java多态的实现机制

南楼画角 提交于 2019-12-04 04:17:53
Java提供了编译时多态和运行时多态两种多态机制。前者是通过方法重载实现的,后者是通过方法的覆盖实现的。   在方法覆盖中,子类可以覆盖父类的方法,因此同类的方法会在父类与子类中有着不同的表现形式。  在Java语言中,基类的引用变量不仅可以指向基类的实例对象,也可以指向其子类中的实例对象。同样,接口中的引用变量也可以指向其实现类的实例对象。而程序调用的方法在运行时期才动态绑定(绑定是指将一个方法调用和一个方法主体联系在一起),绑定的是引用变量所指向的具体实例对象的方法,也就是内存中正在运行的那个对象的方法,而不是引用变量的类型中定义的方法。通过这种动态绑定实现了多态。由于只有在运行时才能确定调用哪个方法,因此通过方法覆盖实现的多态也可以被称为运行时多态。      示例一: 1 public class Base { 2 public Base(){ 3 g(); 4 } 5 6 public void g() { 7 System.out.println("Base g()"); 8 } 9 10 public void f() {11 System.out.println("Base f()");12 }13 } 1 public class Derived extends Base{ 2 3 public void g() { 4 System.out.println(

数据结构实验二

两盒软妹~` 提交于 2019-12-04 04:02:24
#include <stdio.h> #include <stdlib.h> int STACK_INIT_SIZE=100; int STACKINCREMENT=10; typedef struct{ int *base; int *top; int stacksize; }sqstack; void initstack(sqstack &S){ S.base=(int * )malloc(STACK_INIT_SIZE*sizeof(int)); if(!S.base)exit(1); S.top=S.base; S.stacksize=STACK_INIT_SIZE; } int judge(sqstack S){ if(S.top==S.base) return 0; else return 1; } void push(sqstack &S,int e){ if(S.top-S.base>=S.stacksize){ S.base=(int*)realloc(S.base,(S.stacksize+STACKINCREMENT)*sizeof(int)); if(!S.base)exit(1); S.top=S.base+S.stacksize; S.stacksize+=STACKINCREMENT; } *S.top++=e; } void pop(sqstack

How to solve a problem with base tag?

狂风中的少年 提交于 2019-12-04 04:00:52
问题 I have a problem with base tag. It looks like <base href="http://myexamplepage.com/myfolder/" /> . Everything works, besides this query: $.get("application/soft/calendar_month_change.php", ...) My computer thinks it's cross domain server and changes query to OPTIONS .... When I remove the base tag, it works correctly but my site doesn't show any images. I use smarty template engine. How can I solve it? 回答1: How can I solve it? Want my opinion? Don't use base . Exactly for the reason presented

Parsing integer strings in Java [duplicate]

删除回忆录丶 提交于 2019-12-04 03:09:39
This question already has answers here : Closed 8 years ago . Possible Duplicate: How to convert a hexadecimal string to long in java? I know that Java can't handle this: Integer.parseInt("0x64") Instead you have to do this: Integer.parseInt("64", 16) Is there something built into Java that can automatically parse integer strings for me using the standard prefixes for hex, octal, and lack of prefix for decimal (so that I don't have to strip off the prefix and explicitly set the base)? You can use Integer.decode : Integer.decode("0x64"); The decoding rules are as follows: Prefix Type

C++异常(3) - 捕获基类与子类的异常

本小妞迷上赌 提交于 2019-12-03 23:21:49
如果基类和子类都被做为异常捕获,则子类的catch代码块必须出现在基类之前。 如果把基类放在前面,则子类的catch代码块永远都不会被调用。 例如,下面程序打印“Caught Base Exception”。 #include<iostream> using namespace std; class Base {}; class Derived: public Base {}; int main() { Derived d; try { throw d; } catch(Base b) { cout<<"Caught Base Exception"; } catch(Derived d) { //这个catch代码块永远都不会被执行 cout<<"Caught Derived Exception"; } return 0; } 上述程序中,如果调整下声明的顺序,则都可以被捕获。 下面是修改之后的程序,会打印“Caught Derived Exception”。 #include<iostream> using namespace std; class Base {}; class Derived: public Base {}; int main() { Derived d; try { throw d; } catch(Derived d) { cout<<"Caught

Creating base class for Entities in Entity Framework

℡╲_俬逩灬. 提交于 2019-12-03 20:51:19
I would like to create a base class that is somewhat generic for all of my entities. The class would have methods like Save(), Delete(), GetByID() and some other basic functionality and properties. I have more experience with Linq to SQL and was hoping to get some good examples for something similar in the EF. Thank you. Like this: public abstract class BaseObject<T> { public void Delete(T entity) { db.DeleteObject(entity); db.SaveChanges(); } public void Update(T entity) { db.AcceptAllChanges(); db.SaveChanges(); } } public interface IBaseRepository<T> { void Add(T entity); T GetById(int id);

saltstack配置管理

早过忘川 提交于 2019-12-03 19:26:19
#salt的配置文件要遵守YAML格式; #添加file root [root@linux-node1 salt]# vim master file_roots: base: - /srv/salt/base dev: - /ser/salt/dev test: - /srv/salt/test prod: - /srv/salt/prod #手敲,不建议复制,注意空格不要用tab键 #创建相应的目录 [root@linux-node1 salt]# mkdir -p /srv/salt/{base,dev,test,prod} [root@linux-node1 salt]# systemctl restart salt-master #重启后检查服务是否正常 [root@linux-node1 salt]# salt '*' test.ping linux-node2: True linux-node1: True #如果服务异常查看日志 [root@linux-node1 salt]# tailf /var/log/salt/master #通过salt安装apache #创建状态文件 [root@linux-node1 base]# vim apache.sls apache-install: pkg.installed: - name: httpd apache