getchar

read changes stdout from unbuffered to line buffered in canonical mode

点点圈 提交于 2019-12-23 02:36:38
问题 When I use this piece of code in canonical mode: #include <stdio.h> #include <termios.h> #include <unistd.h> static struct termios newt; static struct termios oldt; static void kb_fini(void) { tcsetattr(STDIN_FILENO, TCSANOW, &oldt); } void kb_init(void) { tcgetattr(STDIN_FILENO, &oldt); newt = oldt; newt.c_lflag &= (tcflag_t)~(ICANON | ECHO | ISIG); newt.c_cc[VMIN] = 1; newt.c_cc[VTIME] = 0; tcsetattr(STDIN_FILENO, TCSANOW, &newt); atexit(kb_fini); } int main(void) { int c; kb_init(); printf

getchar not working in switch case (c)

非 Y 不嫁゛ 提交于 2019-12-23 02:18:09
问题 Using a very simple calculator program that prompts a user for an operation to perform, followed by a prompt for two integers on which to perform this operation. The program is supposed to loop after these operations, except in the case where the user enters the character 'q', at which point the program is supposed to quit. #include <stdio.h> int main (void) { char c; int number[2], num1, num2, result; double num1d, num2d, resultd; int done=1; while(done) { printf("\t What sort of operation

the input buffer in getchar() and scanf

拥有回忆 提交于 2019-12-23 01:51:29
问题 Sorry because I can't think of any better title I have a problem dealing with the input Here is my test code which get the input into a string array then print it on screen again, quite simple The 1st test code work fine as expected #include <stdio.h> int main() { int i, index; char d, c[20]; scanf("%d", index); for(i=0; i<index; i++){ *(c+i) = getchar(); if (*(c+i)=='$') break; } printf("the string is %s", c); return 0; } the 2nd test code, I did use pointer but c[i] instead and the program

About storing getchar() returned value inside a char-variable

谁都会走 提交于 2019-12-22 19:26:06
问题 I know the following code is broken -- getchar() returns an int not a char -- #include <stdio.h> int main(int argc, char* argv[]) { char single_byte = getchar(); while (single_byte != EOF) { single_byte = getchar(); printf("getchar() != EOF is %d.\n", single_byte != EOF); if (single_byte == EOF) printf("EOF is implemented in terms of 0x%x.\n", single_byte); } return 0; } though I would expect that a typical output of it (using /dev/urandom as the input-stream for instance) would have been at

整行字符串的读入

主宰稳场 提交于 2019-12-22 18:51:19
方法一: scanf()读入char[] 使用方法: char str[1024]; scanf("%[^\n]",&str); getchar(); 方法二: getchar()读入char[] 使用方法: char str[1024]; int i=0; while((str[i]=getchar())!='\n') i++; getchar(); 方法三: gets()读入char[] 使用方法: char str[1024]; gets(str); 方法四: getline()读入string或char[] 使用方法: string str; getline(cin,str);//读入string char str2[1024]; cin.getline(str2,1024);//读入char数组 方法五: get()读入char[] 使用方法: char str3[1024]; cin.get(str3,1024);//读入char数组 转载自: https://www.cnblogs.com/AlvinZH/p/6798023.html 来源: https://www.cnblogs.com/Miracevin/p/9031665.html

[Wc2011] Xor 和 [HNOI2011]XOR和路径

邮差的信 提交于 2019-12-22 15:12:38
Xor F.A.Qs Home Discuss ProblemSet Status Ranklist Contest 入门OJ ModifyUser autoint Logout 捐赠本站 Problem 2115. -- [Wc2011] Xor 2115: [Wc2011] Xor Time Limit: 10 Sec Memory Limit: 259 MB Submit: 5811 Solved: 2474 [ Submit ][ Status ][ Discuss ] Description Input 第一行包含两个整数N和 M, 表示该无向图中点的数目与边的数目。 接下来M 行描述 M 条边,每行三个整数Si,Ti ,Di,表示 Si 与Ti之间存在 一条权值为 Di的无向边。 图中可能有重边或自环。 Output 仅包含一个整数,表示最大的XOR和(十进制结果),注意输出后加换行回车。 Sample Input 5 7 1 2 2 1 3 2 2 4 1 2 5 1 4 5 3 5 3 4 4 3 2 Sample Output 6 HINT Source [ Submit ][ Status ][ Discuss ] HOME Back 한국어 中文 فارسی English ไทย 版权所有 ©2008-2018 大视野在线测评 |

lca最近公共祖先(模板)

痴心易碎 提交于 2019-12-21 11:59:34
洛谷上的lca模板题—— 传送门 1.tarjan求lca 学了求lca的 tarjan算法(离线) ,在洛谷上做模板题,结果后三个点超时。 又把询问改成链式前向星,才ok。 这个 博客 ,tarjan分析的很详细。 附代码—— #include <cstdio> #include <cstring> const int maxn = 500001; int n, m, cnt, s, cns; int x, y, z[maxn];//z是x和y的lca int f[maxn], head[maxn], from[maxn]; bool vis[maxn]; struct node { int to, next; }e[2 * maxn]; struct Node { int to, next, num; }q[2 * maxn]; inline int read()//读入优化 { int x = 0, f = 1; char ch = getchar(); while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); } while(ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; }

AtCoder Grand Contest 003

99封情书 提交于 2019-12-21 09:06:32
AtCoder Grand Contest 003 A - Wanna go back home 翻译 告诉你一个人每天向哪个方向走,你可以自定义他每天走的距离,问它能否在最后一天结束之后回到起点。 题解 什么逗逼东西。。。 #include<cstdio> #include<cstring> using namespace std; char s[1010]; bool W,E,S,N; int main() { scanf("%s",s+1); for(int i=1,l=strlen(s+1);i<=l;++i)W|=s[i]=='W',E|=s[i]=='E',S|=s[i]=='S',N|=s[i]=='N'; if((W^E)||(N^S))puts("No");else puts("Yes"); return 0; } B - Simplified mahjong 翻译 你有写着 \([1,n]\) 的卡片若干张,写着 \(i\) 的有 \(a_i\) 张,两两卡片可以配对当且仅当它们上面写的数字差的绝对值小于等于 \(1\) ,求最大配对数。 题解 什么鬼玩意。。。。 然而yyb怒交4发才AC #include<iostream> #include<cstdio> using namespace std; #define MAX 100100 #define ll

求逆序对的两种方法(树状数组/归并排序)

末鹿安然 提交于 2019-12-21 08:49:32
例题:poj2299 看代码就好了 树状数组: #include<iostream> #include<cstdio> #include<queue> #include<string> #include<string.h> #include<set> #include<stack> #include<vector> #include<algorithm> #include<cmath> #include<iterator> #define mem(a,b) memset(a,b,sizeof(a)) #define MOD 100000007 #define ll long long #define INF 0x3f3f3f3f const double pi = acos(-1.0); const int Maxn=50000; using namespace std; inline int scan() { int x=0,c=1; char ch=' '; while((ch>'9'||ch<'0')&&ch!='-')ch=getchar(); while(ch=='-')c*=-1,ch=getchar(); while(ch<='9'&&ch>='0')x=x*10+ch-'0',ch=getchar(); return x*c; } /****************

GetKeyState() vs. GetAsyncKeyState() vs. getch()?

£可爱£侵袭症+ 提交于 2019-12-20 18:05:04
问题 What's the difference between getting a key press with: GetKeyState() GetAsyncKeyState() getch() ? When should I use one over the other? 回答1: GetKeyState() and GetAsyncKeyState() are Windows specific APIs, while getch() works on other non-Windows-specific C compilers. GetKeyState() gets the key status returned from the thread's message queue . The status does not reflect the interrupt-level state associated with the hardware. GetAsyncKeyState() specifies whether the key was pressed since the