freopen

AtCoder-abc147 (题解)

依然范特西╮ 提交于 2019-12-12 09:30:13
A - Blackjack (水题) 题目链接 大致思路: 水题 B - Palindrome-philia (水题) 题目链接 大致思路: 由于整个串是回文串,只要判断前一半和后一半有多少个不同即可 C - HonestOrUnkind2 (暴力) 题目链接 大致思路: \(N\) 只有15,直接枚举出所有的情况 \(2^N\) 种,对每一种方案判断合法性即可,只要找诚实的人来判断。 点击展开代码 #include<bits/stdc++.h> using namespace std; vector<int>x[20],y[20]; int n; int js(int x){ int ans=0; while(x){ ans+=(x&1); x>>=1; } return ans; } bool check(int X){ int temp[20]={0}; for(int i=1;i<=n;i++){ if((X>>(i-1))&1)temp[i]=1; else temp[i]=0; } for(int i=1;i<=n;i++){ if(temp[i]){ int siz=x[i].size(); for(int j=0;j<siz;j++){ int id=x[i][j]; if((temp[id]^y[i][j])==1)return 0; } } } return 1

Swift stderr and stout into single file

强颜欢笑 提交于 2019-12-12 04:23:04
问题 For an iPhone app, I need to collect debugging data into a file to be sent to an online service for analysis. This works fine by diverting the stderr output to a file handle and sending the file when appropriate. ( NSLog output also ends up in stderr , so this works across the board.) The same method also works fine with stdout . Here is how I do the saving to a file: freopen(cStringFilePath, "a+", stderr) // or stdout The above correctly returns a UnsafeMutablePointer<FILE> which I keep

CSP-S 2019复赛游记

房东的猫 提交于 2019-12-11 02:20:21
目录 Day -1 Day 0 Day 1 考前 考中 考后 做法&程序(考场做法,不能AC) 格雷码 括号树 树上的数 Day 2 考前 考中 考后 做法&程序(考场做法,不能AC) Emiya 家今天的饭 划分 树的重心 Day 3+(后记&提醒) date: 2019-11-15 前言:想直接进入正题请跳转到Day 1。 Day -1 明天我就去南京了,感到非常的紧张, 毕竟CSP和NOIP没有关系,没有真题可以刷(逃 。 注:对于内心中难度的比较,是对于NOIP提高组的题目比较的。 Day 0 坐了一趟一个小时却感觉像是一天的火车,终于到了南京。到了南京就去南航去报到,报到完了就去三食堂的二楼吃饭,比学校的饭菜要好吃(SAN值++)。晚上和同学家长吃饭,互相鼓(mo)励(bai)一番以排解压力。回来之后写写线段树(对的,我喜欢写线段树),只需要一点点时间就可以让自己变得开心起来 (大雾) 。 总的来说,在没有被Day1血虐之前,我今天还是比较开心的。 Day 1 考前 进入考场没有什么大问题。试机前半段时间脑抽,bits之类的板子和提醒自己的东西都好久才想起来打,后半段花了大半段时间在搞懂怎么提交 (话说我好像曾经来打过一次比赛来着怎么忘了) ,导致自己没有听清试题电子档的位置,心态瞬间跌入谷底。考前的提醒是放的NOIP2018的,很好笑,考场的人都笑了,稍稍缓解了气氛

How to write in stdout after using freopen [duplicate]

半城伤御伤魂 提交于 2019-12-10 11:08:16
问题 This question already has answers here : How to redirect the output back to the screen after freopen(“out.txt”, “a”, stdout) (6 answers) Closed 5 years ago . After freopen -ing stdout , How can I print on terminal? freopen("out", "w", stdout); // reopen stdout /* something */ printf("Now I want to print this on terminal"); 回答1: I believe this is what you are looking for: Once I've used freopen, how can I get the original stdout (or stdin) back? There's no portable solution. But the link also

ACMer菜鸟心得之ACM的输入

混江龙づ霸主 提交于 2019-12-09 23:41:33
  大一开始了解ACM,兴趣使然,看了些刘汝佳写的书,颇有心得,于是记录下来,不定时更新。   ACM的输入:    #define LOCAL #include <stdio.h> int main() { #ifdef LOCAL freopen("data.in","r",stdin); freopen("data.out","w",stdout); #endif printf("Hello World!\n"); return 0; } 这是一份比较典型的竞赛代码,其中采用的是重定向的方法,build该代码时,系统会在当前目录下自动生成data.in和data.out两个文件,顾名思义,输入部分保存在data.in中,输出部分保存在data.out中,再和OJ系统评判,重定向的部分被写在#ifdef和#endif之间,其意义为:只有定义了LOCAL,才能编译两条freopen语句。 另外,C语言里的很多缩写,知道全称后,你能对其有更深的理解,例如,stdio全称为Standard Input and Ouput(标准输入输出),stdlib全称为standard libarary(标准库)。 ACM的输入(凭我的阅历)有以下几种: 1.直接输入  //不多说 2.多组输入 多组输入分为两种,一种是输入一个案例后,立马输出该案例的结果 #include <stdio.h>

CSP-S2019题解

天大地大妈咪最大 提交于 2019-12-07 07:48:28
代码先贴上,题解咕咕咕 D1T1 判断每一位是否超过一半,如果超了就把后面的反过来 注意 #include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> #define fo(a,b,c) for (a=b; a<=c; a++) #define fd(a,b,c) for (a=b; a>=c; a--) using namespace std; unsigned long long p[64]; unsigned long long m; int n,i,j,k,l; int main() { freopen("code.in","r",stdin); freopen("code.out","w",stdout); p[0]=1; fo(i,1,63) p[i]=p[i-1]*2; cin>>n>>m; fd(i,n-1,0) if (m<p[i]) printf("0"); else printf("1"),m=p[i]-(m-p[i])-1; printf("\n"); fclose(stdin); fclose(stdout); return 0; } D1T2 #include <algorithm> #include <iostream>

如何优雅地将printf的打印保存在文件中?

旧城冷巷雨未停 提交于 2019-12-06 22:10:40
我们都知道,一般使用printf的打印都会直接打印在终端,如果想要保存在文件里呢?我想你可能想到的是重定向。例如: $ program > result.txt 这样printf的输出就存储在result.txt中了。 当然了,如果你既想打印在终端,又想保存在文件,还可以使用tee命令: program | tee result.txt 注:program为你运行的程序。 不过文本介绍了不是通过命令行的方式,而是通过代码实现。 写文件 你可能会想,那不用printf,直接将打印写入到文件不就可以了?类似于下面这样: #include<stdio.h> int main(void) { FILE *fp = fopen("log.txt","w+"); if(NULL == fp) { printf("open failed "); return -1; } int a = 10; fprintf(fp,"test content %d ",a); fclose(fp); return 0; } 不过这需要将原先的printf改用fprintf,修改了最原始的代码。但是本文并不是说明如何实现一个logging功能,而是如何将printf的原始打印保存在文件中。 重定向 实际上,我们的程序在运行起来后,都会有三个文件描述符: 0 标准输入 1 标准输出 2 标准错误

Trying to create an output file with freopen, using non-constant string

 ̄綄美尐妖づ 提交于 2019-12-06 16:47:56
问题 I'm trying to create a file whose name is a string constant, but a string consisting of a constant string "List" an integer + + an extension. Here's my code: #include <iostream> #include <vector> #include <iostream> #include <fstream> #include <iomanip> #include <string> using namespace std; int main (){ int cont=0; std::string result; std::string name = "Lista"; std::string ext = ".txt"; char numstr[21]; // enough to hold all numbers up to 64-bits sprintf(numstr, "%d", cont); result = name +

#2019110700005

℡╲_俬逩灬. 提交于 2019-12-06 15:16:41
大意 给定 \(A,B,C\) ,其中每个时速满足 \(A \leq v \leq B\) ,如果不满足则记作超速,共有 \(C\) 个时速,其中有 \(F\) 个超速,如果 \(\frac {F}{C}>10\%\) ,则输出“ \(broken\) ”,否则输出未超速的速度的平均值,保留4位小数. 思路 模拟 注意 不要用样例里的数据!!!!!! 不要瞎用define!!!!!!!! 结构体做法 #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> #define file(s) freopen(s".in","r",stdin);freopen(s".out","w",stdout); #define dn(s) s+1+s+2+3 #define jiangui cnt=0; using namespace std; int A,B,C; int jiangui //int sta[405]; struct s{ int s; int u; }sta[405]; int tot=0; int cnnnnt; int main(){ // freopen("radar.in","r",stdin); // freopen("radar.out","w",stdout); file(

AtCoder-arc060 (题解)

时光总嘲笑我的痴心妄想 提交于 2019-12-06 15:13:34
A - 高橋君とカード / Tak and Cards (DP) 题目链接 题目大意: 有 \(n\) 个数字,要求取出一些数字,使得它们的平均数恰好为 \(x\) ,问有几种取法。 大致思路: 只要将每一个数字减掉 \(x\) ,那么问题就变成在 \(n\) 个数字中选取一些数字使得和为 \(0\) 的方案数,是一个经典的 \(dp\) 问题,不过要注意细节问题 代码: #include<bits/stdc++.h> #define ll long long using namespace std; const int N=5010; const int Y=2500; ll dp[N][N]; int n,x; int a[N]; int main() { //freopen("H:\\c++1\\in.txt","r",stdin); //freopen("H:\\c++1\\out.txt","w",stdout); scanf("%d%d",&n,&x); dp[0][Y]=1; for(int i=1;i<=n;i++)scanf("%d",&a[i]),a[i]-=x; for(int i=1;i<=n;i++){ for(int j=-Y;j<=Y;j++){ dp[i][j+Y+a[i]]+=dp[i-1][j+Y]; dp[i][j+Y]+=dp[i-1][j