fread

ACM中的fread读入

百般思念 提交于 2020-03-15 16:33:31
fread可以加快读入速度,尤其是读特大的二进制文件。 #include <cctype> typedef long long LL; char buf[100000],*p1=buf,*p2=buf; inline char nc(){ return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++; } inline bool rea(int & x){ char c=nc();x=0; if(c==EOF) return false; for(;!isdigit(c);c=nc()); for(;isdigit(c);x=x*10+c-'0',c=nc()); return true; } inline bool rea(LL & x){ char c=nc();x=0; if(c==EOF) return false; for(;!isdigit(c);c=nc()); for(;isdigit(c);x=x*10+c-'0',c=nc()); return true; } ps. 向lyg要的代码。处理负数需要自己加上去。 来源: https://www.cnblogs.com/flipped/p/7253311.html

从discuz里面拿来的东东[转phpx]

懵懂的女人 提交于 2020-01-31 00:20:54
<?php 加解密函数 $encode = authocode ( '我要加密' , 'ENCODE' ); $decode = authocode ( '我要解密' , 'DECODE' ); $auth_key = 34577 ; //密钥 function authcode ( $string , $operation , $key = '' ) { $key = md5 ( $key ? $key : $GLOBALS [ 'auth_key' ]); $key_length = strlen ( $key ); $string = $operation == 'DECODE' ? base64_decode ( $string ) : substr ( md5 ( $string . $key ), 0 , 8 ). $string ; $string_length = strlen ( $string ); $rndkey = $box = array(); $result = '' ; for( $i = 0 ; $i <= 255 ; $i ++) { $rndkey [ $i ] = ord ( $key [ $i % $key_length ]); $box [ $i ] = $i ; } for( $j = $i = 0 ; $i < 256 ; $i ++)

PHP转换IP地址到真实地址

与世无争的帅哥 提交于 2020-01-31 00:16:54
想要把IPv4地址转为真实的地址,肯定要参考IP数据库,商业的IP数据库存储在关系型数据库中,查询和使用都非常方便,但是成本不是个人和小公司愿意承受的,所以简单应用的思路就是利用一些免费的IP数据库或者一些大网站提供的查询API,他们的数据量足够我们使用了。 1. 利用纯真IP数据库 利用本地的QQWry.Dat文件,优点是查询速度非常快,缺点是数据库文件要放在自己的空间内并且要偶尔更新数据库。时间关系废话不多说,下面是使用这个文件的函数,如果是在wordpress里面使用这个功能,把下面的代码写入主题下面的functions.php里面,然后在comments-list的输出<?php echo convertip(get_comment_author_ip()); ?>即可;如果是其他程序引用,输入一个有效的IPv4地址就可以得到一个真实的地址。 function convertip($ip) { //IP数据文件路径 $dat_path = 'QQWry.Dat'; //检查IP地址 //if(!preg_match("/^d{1,3}.d{1,3}.d{1,3}.d{1,3}$/", $ip)) { // return 'IP Address Error'; //} //打开IP数据文件 if(!$fd = @fopen($dat_path, 'rb')){ return

php上传zip文件在线解压文件在指定目录下,CI框架版本

隐身守侯 提交于 2020-01-26 18:54:01
我从网上找的文件php在线解压zip压缩文件 文件为jy.php可以直接执行,但是怎样将其加到CI框架中呢?? jy.php文件 1 <?php 2 header("content-Type: text/html; charset=utf-8"); 3 //验证密码 4 $password = "123456"; 5 ?> 6 <html> 7 <head> 8 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 9 <title>在线解压ZIP文件程序 V1.0</title> 10 <style type="text/css"> 11 <!-- 12 body,td{ 13 font-size: 14px; 14 color: #000000; 15 } 16 a { 17 color: #000066; 18 text-decoration: none; 19 } 20 a:hover { 21 color: #FF6600; 22 text-decoration: underline; 23 } 24 --> 25 </style> 26 </head> 27 28 <body> 29 <form name="myform" method="post" action="<?=$_SERVER

远程获取图片尺寸

我与影子孤独终老i 提交于 2020-01-26 18:48:17
<?php /** * 获取远程图片的宽高和体积大小 * * @param string $url 远程图片的链接 * @param string $type 获取远程图片资源的方式, 默认为 curl 可选 fread * @param boolean $isGetFilesize 是否获取远程图片的体积大小, 默认false不获取, 设置为 true 时 $type 将强制为 fread * @return false|array */ function myGetImageSize($url, $type = 'curl', $isGetFilesize = false) { // 若需要获取图片体积大小则默认使用 fread 方式 $type = $isGetFilesize ? 'fread' : $type; if ($type == 'fread') { // 或者使用 socket 二进制方式读取, 需要获取图片体积大小最好使用此方法 $handle = fopen($url, 'rb'); if (! $handle) return false; // 只取头部固定长度168字节数据 $dataBlock = fread($handle, 168); } else { // 据说 CURL 能缓存DNS 效率比 socket 高 $ch = curl_init(

Reading seperate text files and saving them in a single variable as seperate dataframes

╄→尐↘猪︶ㄣ 提交于 2020-01-24 21:47:29
问题 I have multiple text files (tab-delimited) generated from the same software. I initially used a loop with assign function to create variables dynamically and store them separately with the read.table function. This resulted in too many variables and was obviously time-consuming to apply operations on separate files. I came across the lapply and fread method shown in the code below. I don't need to merge them and they need to be separate data frames so I can compare values in the files. Using

check return value fread and fwrite

元气小坏坏 提交于 2020-01-23 02:42:48
问题 #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]){ if(argc != 3){ printf("Usage: ./copy filename newfile\n"); exit(1); } int bytes; long file_size, file_copied_size; FILE *file_to_copy, *new_file; if((file_to_copy = fopen(argv[1], "rb")) == NULL){ printf("File cannot be opened - read\n"); exit(1); } if((new_file = fopen(argv[2], "wb")) == NULL){ printf("File cannot be opened - write\n"); exit(1); } fseek(file_to_copy, 0, SEEK_END); file_size = ftell(file_to_copy); rewind

fread from data.table package when column names include spaces and special characters?

别等时光非礼了梦想. 提交于 2020-01-21 06:40:27
问题 I have a csv file where column names include spaces and special characters. fread imports them with quotes - but how can I change this behaviour? One reason is that I have column names starting with a space and I don't know how to handle them. Any pointers would be helpful. Edit: An example. > packageVersion("data.table") [1] ‘1.8.8’ p2p <- fread("p2p.csv", header = TRUE, stringsAsFactors=FALSE) > head(p2p[,list(Principal remaining)]) Error: unexpected symbol in "head(p2p[,list(Principal

Is it correct to check if the number of items read is less than requested, rather than 0, in fread(3)?

喜欢而已 提交于 2020-01-17 03:50:06
问题 I'm a beginner to C. I was wondering if it correct to check if the return value of fread(3) (which is the number of items read) is less than the number requested, rather than just 0, to detect EOF. For example, say you have #include <stdio.h> int main(void) { unsigned char buffer[1024]; while (fread(buffer, 1, sizeof(buffer), stdin) == sizeof(buffer)) { printf("%s\n", "Not EOF yet"); } printf("%s\n", "At EOF"); return 0; } Is this correct? Should the check for == sizeof(buffer) be != 0

PHP giving a trailing “=” on each line after reading from stdin

风流意气都作罢 提交于 2020-01-15 03:45:31
问题 The contents of stdin is getting corrupted with word wrapping and trailing "=" throughout which obviously breaks the URL that I need to post. I need to extract a URL/link from an email then post the URL. So, I'm piping my email to a php script in cpanel using a standard code snip I've seen all over the internet: $fd = fopen("php://stdin", "r"); $email = ""; // This will be the variable holding the data. while (!feof($fd)) { $email .= trim(fread($fd, 1024)); } fclose($fd); Then dumping the