Browsed by
Category: Water

把基本输入 scanf getchar gets 的区别

把基本输入 scanf getchar gets 的区别

在写控制台程序的时候,难免会遇到各种各样的输入格式读取,下面比较一下 scanf  getchar 和 gets的区别 首先我们要知道,当用户从键盘键入一个字符串的时候,就会在IO缓冲区内写入信息,这个缓冲区是一个队列,  我们用下面几段代码来检验一下,不同函数对缓冲区的读取效果 这一段代码是测试这三个函数到底读取了哪些字符 代码如下 /************************************************************************* > File Name: a.cpp > Author: VOID_133 > ################### > Mail: ################### > Created Time: 2014年10月26日 星期日 00时43分53秒 ************************************************************************/ #include<iostream> #include<algorithm> #include<cstdio> #include<vector> #include<cstring> #include<map> #include<queue> #include<stack> #include<string> #include<cstdlib> #include<ctime> #include<set> using namespace std; int main(void) { char s[30]; //scanf(“%s”,s); //gets(s); int len=strlen(s); for(int i=0;i<len;i++) { if(s[i]==’n’) s[i]=’#’; if(s[i]==’t’) s[i]=’$’;                 if(s[i]==’ ‘) s[i]=’@’; } printf(“%s”,s); return 0; } 这段代码中,首先用注释掉的scanf来接受输入  输入 test加回车后 输出的只有…

Read More Read More

BNU Contest 8-28 A

BNU Contest 8-28 A

A. Magic Number Time Limit: 2000ms Memory Limit: 32768KB 64-bit integer IO format: %lld     Java class name: Main A positive number y is called magic number if for every positive integer x it satisfies that put y to the right of x, which will form a new integer z, z mod y = 0. Input The input has multiple cases, each case contains two positve integers m, n(1 <= m <= n <= 2^31-1), proceed to the end of…

Read More Read More

BNU Contest 8-26 G. Gao The Sequence

BNU Contest 8-26 G. Gao The Sequence

BNU Contest 8-26 竞赛题目链接点击这里 G. Gao The Sequence Time Limit: 2000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      Java class name: Main You are given a sequence of integers, A1,A2,…,An. And you are allowed a manipulation on the sequence to transform the origin sequence into another sequence B1,B2,…,Bn(Maybe the two sequences are same ). The manipulation is specified as the following three steps: 1.Select an integer Ai and choose an arbitrary positive integer delta as you like. 2.Select…

Read More Read More

BNU Contest 8-26 F. Japanese Mahjong III

BNU Contest 8-26 F. Japanese Mahjong III

BNU Contest 8-26 竞赛题目链接点击这里 F. Japanese Mahjong III Time Limit: 2000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      Java class name: Main Mahjong is a game of skill, strategy and calculation and involves a certain degree of chance. In this problem, we concentrate on Japanese Mahjong, a variation of mahjong. For brief, all of the word mahjong mentioned following refer to Japanese Mahjong.     Japanese mahjong is usually played with 136 tiles, which can be organized into…

Read More Read More