putchar

牛客NOIP暑期七天营-提高组2

这一生的挚爱 提交于 2019-11-28 01:29:41
第一题:ACGT 题目链接: https://ac.nowcoder.com/acm/contest/931/A trie树、hash、map遍历   ①、trie树上的节点多记一个rest值表示还有多少个串没被用。枚举所有串, 每次先在trie上跑匹配串,看一看那个点的rest。如果没法匹配的话就往trie里插入原串,把结束节点的rest+1   ②、思路和trie类似。其实就是把trie换成hash。(把在树上跑换成去hash值)   ③、将每个序列的个数存下,每次读入时判断对应序列的map的权值是否为0,若不为0,将输入序列和其对应序列的map权值-- ,ans++ 下面是第三种解法 : 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define ll long long 4 #define inf 0x3f3f3f 5 ll read() 6 { 7 ll res=0,flag=0; 8 char ch; 9 if((ch=getchar())=='-')flag=1; 10 else if(ch>='0'&&ch<='9')res=ch-'0'; 11 while((ch=getchar())>='0'&&ch<='9')res=res*10+(ch-'0'); 12 return flag?-res:res;

Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3)

安稳与你 提交于 2019-11-28 00:40:38
A.Math Problem(CF 1262 A) 题目大意:给定n条线段,求一条线段,使得这个线段能够跟所有给定的线段都相交(端点值一样也算相交),最小化它的长度,可以是0. 很显然找出这n条线段的左端点最大值和右端点的最小值,它们的差和0的最大值即为答案。 1 #include <bits/stdc++.h> 2 #define MIN(a,b) (((a)<(b)?(a):(b))) 3 #define MAX(a,b) (((a)>(b)?(a):(b))) 4 using namespace std; 5 6 template <typename T> 7 void read(T &x) { 8 int s = 0, c = getchar(); 9 x = 0; 10 while (isspace(c)) c = getchar(); 11 if (c == 45) s = 1, c = getchar(); 12 while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); 13 if (s) x = -x; 14 } 15 16 template <typename T> 17 void write(T x, char c = ' ') { 18 int b[40], l = 0; 19

Theory Behind getchar() and putchar() Functions

梦想与她 提交于 2019-11-27 23:14:07
I'm working through "The C Programming Language" by K&R and example 1.5 has stumped me: #include <stdio.h> /* copy input to output; 1st version */ int main(int argc, char *argv[]) { int c; while ((c = getchar()) != EOF) putchar(c); return 0; } I understand that 'getchar()' takes a character for 'putchar()' to display. However, when I run the program in terminal, why is it that I can pass an entire line of characters for 'putchar()' to display? Because your terminal is line-buffered. getchar() and putchar() still only work on single characters but the terminal waits with submitting the

getchar() != EOF

﹥>﹥吖頭↗ 提交于 2019-11-27 15:43:34
I am running the following program from the C Programming Language book: #include <stdio.h> main() { int c; while((c=getchar()) != EOF) putchar(); } Or #include<stdio.h> int main(){ int c = getchar(); while(c != EOF){ putchar(c); c = getchar(); } } When I run this program, I get an unexplained behavior. If I input characters from the command line in the following sequence: {'h', 'e', 'l', 'l', 'o', '\n', '^D'} then I get the following response printed to screen: hello , after \n is input, and the program quits once ^D in entered. However, when I change the sequence as follows: {'h', 'e', 'l',

I'm trying to understand getchar() != EOF

China☆狼群 提交于 2019-11-27 06:54:10
I'm reading The C Programming Language and have understood everything so far. However when I came across the getchar() and putchar() , I failed to understand what is their use, and more specifically, what the following code does. main() { int c; while ((c = getchar()) != EOF) putchar(c); } I understand the main() function, the declaration of the integer c and the while loop. Yet I'm confused about the condition inside of the while loop. What is the input in this C code, and what is the output. Sorry if this is a basic and stupid question, but I'm just looking for a simple explanation before I

Why putchar, toupper, tolower, etc. take a int instead of a char?

十年热恋 提交于 2019-11-27 03:51:45
问题 In C, strings are arrays of char ( char * ) and characters are usually stored in char . I noticed that some functions from the libC are taking as argument integers instead of a char. For instance, let's take the functions toupper() and tolower() that both use int . The man page says: If c is not an unsigned char value, or EOF, the behavior of these functions is undefined. My guess is that with a int , toupper and tolower are able to deal with unsigned char and EOF . But in fact EOF is in

兔八哥与猎人

折月煮酒 提交于 2019-11-27 00:06:14
【问题描述】 2兔八哥躲藏在树林旁边的果园里。果园有 M × N 棵树,组成一个 M 行 N 列的矩阵,水 平或垂直相邻的两棵树的距离为 1。兔八哥在一棵果树下。 猎人背着猎枪走进了果园,他爬上一棵果树,准备杀死兔八哥。 如果猎人与兔八哥之间没有其它的果树,猎人就可以看到兔八哥。 现己知猎人和兔八哥的位置,编写程序判断兔子所在的位置是否安全 【输入文件】 输入文件 rabbit.in 第一行为 n,表示有 n(n ≤ 100,000)组数据,每组数据的第一行为两 个正整数 ax 和 ay,表示猎人的位置,第二行为两个正整数 bx 和 by,表示兔八哥的位置(1 ≤ ax, ay, bx, by ≤ 100,000,000)。 【输出文件】 输出文件 rabbit.out 共有 n 行,每行为“yes”或“no”表示兔八哥的位置是否安全。 【输入 1】 1 1 1 1 2 【输出 1】 no 【输入 2】 1 1 1 1 3 【输出 2】 yes 没啥说的... 求直线上有无整数点 #include <iostream> #include <cstdio> #include <cmath> using namespace std; #define R register inline int gcd(int x,int y){return y?gcd(y,x%y):x;} int n;

getch and putchar not working without return

本小妞迷上赌 提交于 2019-11-26 21:58:09
问题 I have been trying to get getch to work in another program with no success. So I have made the most basic program I can using getch the way I want it to work in the main program. I have researched the need for noecho , cbreak , initscr and nodelay , I have also tried using newscr() but to no success. The problem I am having is that the chars aren't being printed to the screen till I hit "enter", when they should be put to the screen every loop. Why is this happening? Also the cursor doesn't

getchar() != EOF

ε祈祈猫儿з 提交于 2019-11-26 17:17:06
问题 I am running the following program from the C Programming Language book: #include <stdio.h> main() { int c; while((c=getchar()) != EOF) putchar(); } Or #include<stdio.h> int main(){ int c = getchar(); while(c != EOF){ putchar(c); c = getchar(); } } When I run this program, I get an unexplained behavior. If I input characters from the command line in the following sequence: {'h', 'e', 'l', 'l', 'o', '\n', '^D'} then I get the following response printed to screen: hello , after \n is input, and

I&#39;m trying to understand getchar() != EOF

怎甘沉沦 提交于 2019-11-26 12:11:27
问题 I\'m reading The C Programming Language and have understood everything so far. However when I came across the getchar() and putchar() , I failed to understand what is their use, and more specifically, what the following code does. main() { int c; while ((c = getchar()) != EOF) putchar(c); } I understand the main() function, the declaration of the integer c and the while loop. Yet I\'m confused about the condition inside of the while loop. What is the input in this C code, and what is the