the-method-of-programming-1

1.1的举一反三

单词翻转

1
2
Input:"I am a student."
Output: "student. a am I"

尝试使用三步反转,按空格分词,先对每个词反转再整体反转

1
2
3
I am a student.
I ma a .tneduts
student. a am I
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
string reverseWord(string str)
{
stringstream ss(str);
string tmp;
string result;
ss >> tmp;
reverse(tmp.begin(), tmp.end());
result += tmp;

while (ss >> tmp)
{
reverse(tmp.begin(), tmp.end());
result += " ";
result += tmp;
}
reverse(result.begin(), result.end());
return result;
}

1.4

in a word, 临时变量溢出

计算机对int溢出的处理

比如一个4字节的int类型1052254545

1
2
int n = 1052254545;
int m = n * 10; //1932610858

正常情况下m应该为10522545450,但这个数的二进制位有34位,int在这里只能保存32位,所以只会保留后32位

1
2
3
4
5
//10522545450
10 0111 0011 0011 0001 0100 1101 0010 1010

//1932610858
0111 0011 0011 0001 0100 1101 0010 1010

1.6 Manacher算法

12212321

$#1#2#2#1#2#3#2#1#

S[i] # 1 # 2 # 2 # 1 # 2 # 3 # 2 # 1 #
P[i] 1 2 1 2 5 2 1 4 1 2 1 6 1 2 1 2 1

max(P[i] - 1)是原字符串中最长回文子串的长度

codeigniter-1

1.去除url中的index.php

Apache24/conf/httpd.conf

去除下面这行的注释

1
LoadModule rewrite_module modules/mod_rewrite.so

改下下面这个部分(原来是AllowOverride None)

1
2
3
4
5
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride All

system同级目录下的.htaccess

1
2
3
4
5
6
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

如果不是wwwhtdocs的根目录就加上项目名,如这里的tutorial

1
RewriteRule ^(.*)$ /tutorial/index.php/$1 [L]

application/config/config.php

1
$config['index_page'] = "";

2.js,css,images的存放路径填写

3.路由

4.出现http://[::1]

application/config/config.php下的base_url不要设置为空

1
2
3
$config['base_url'] = 'http://localhost/projectname/';

$config['base_url'] = 'http://www.example.com/';
  1. 连接数据库

References

  1. https://blog.csdn.net/k8080880/article/details/77451307

  2. CI框架中base_url关于[::1]的问题