Browsed by
分类:Water

把基本输入 scanf getchar gets 的区别

把基本输入 scanf getchar gets 的区别

在写控制台程序的时候,难免会遇到各种各样的输入格式读取,下面比较一下 scanf  getchar 和 gets的区别

首先我们要知道,当用户从键盘键入一个字符串的时候,就会在IO缓冲区内写入信息,这个缓冲区是一个队列,  我们用下面几段代码来检验一下,不同函数对缓冲区的读取效果

这一段代码是测试这三个函数到底读取了哪些字符

代码如下

这段代码中,首先用注释掉的scanf来接受输入  输入 test加回车后 输出的只有 test  输入test+tab也是同样的输出,这说明 scanf读取缓冲区时,每一次读取读到TAB 和 ENTER 前 (空格就不用说了 当然不读 ) 当scanf被调用时缓冲区里最前面的元素为有回车和空格符 或TAB scanf直接跳过他们不读

同理测试 gets  发现 gets每一次读取到一个回车前,TAB 和SPACE 它都读。当gets被调用时,缓冲区内第一个元素为ENTER时,gets不读这个ENTER

再测试getchar 简单修改代码即可测试  getchar 会读取所有的字符,但是只有当遇到回车的时候才会输出  这种性质叫务回显,而与它不同的 getch就有回显

 

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 file.

Output

For each case, output the total number of magic numbers between m and n(m, n inclusively).

Sample Input

Sample Output

这个题就是找找规律,把满足条件的y都给写出来  就成了这个序列 1 2 5 10 20 25 50 100 125 200 250 500 1000 1250 。。。 可以看到 从第5个数开始 ,每5个数一组,相邻两组相同组内位置的数差10倍  而 2^32最大不超过 10^9所以最多只有 45个数 ,打表就能过

代码:

 

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 some integers Aj satisfying j < i, let’s suppose the selected integers are Ak1,Ak2,…,Akt , then subtract an arbitrary positive integer Di from Aki (1 ≤ i ≤ t) as long as sum(Di) = delta.

3.Subtract delta from Ai.

The manipulation can be performed any times. Can you find a way to transform A1,A2,…,An to B1,B2,…,Bn ?

Input

The input consist of multiple cases. Cases are about 100 or so. For each case, the first line contains an integer N(1 ≤ N ≤ 10000) indicating the number of the sequence. Then followed by N lines, ith line contains two integers Ai and Bi (0 ≤ Bi ≤ Ai ≤ 4294967296).

Output

Output a single line per case. Print “YES” if there is a certain way to transform Sequence A into Sequence B. Print “NO” if not.

Sample Input

Sample Output

这个题也就是看起来有些吓人而已 = =  实际上水的不行

既然我可以任选delta那就表明我可以选择delta为2  每次都把两个数各减掉一,如果能够减到零,即差值的和是偶数的话 那么就可以了 ,如果做不到 ,那么别的方法也做不到 ,因为每次减二已经是必定可行的策略了 ,可以保证在数据符合题意的情况下,最后sumdelta(差值的和)=0  然后加两个特判,一个就是如果sumdelta为奇数,一定不行,另一个就是 如果有一个差值大于了sumdelta/2那么他不可能减到零  ,,然后就没有什么需要注意的了

 

代码:

 

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 several categories:

 

 

  • Suited tiles. All suited tiles are of a rank and a suit.There are three suits of tiles, with ranks ranging from one to nine. There are four tiles of each rank and suit combination, thus there are 36 tiles in a suit, and 108 suited tiles in total.
    • The circle suit
    • The bamboo suit
    • The character suit
  • Honor tiles. Honor Tiles are tiles that do not have a rank or suit. They are divided into two categories. There are four types of Wind tiles and three types of Dragon tiles, with four of each type of honor tile. Thus, there are 16 wind tiles and 12 Dragon tiles for 28 honor tiles.
    • Wind tiles. The Wind tiles consist of four kinds of tile: East, South, West, and North.
    • Dragon tiles. The Dragon titles consist of three types of tile: Red, Green, White.

In this problem, we introduce two abnormal kinds of winning hand different from the normal winning hand, which consist of four melds and one eyes.

  1. Seven Pairs: the hand consists of seven different pairs. No two pairs are the same. For example:
  2. Thirteen Orphans: the hand consists of thirteen kinds of tiles: Circle One, Circle Nine, Bamboo One, Bamboo Nine, Character One, Character Nine, East, South, West, North, Red, Green and White. Only one kind of them are two tiles, while the others are all only one tile. For example:

Now, given a hand with 14 tiles, can you answer this hand is which kind of abnormal kind of winning hand?

Input

There are multiple cases. Each case consists of 28 characters in one line, describing 14 tiles. The manner for describing each type of tile is:

  • Two characters stand for one tile.
  • For Suited tiles, the first is a integer ranged from one to nine, the tile’s rank, and the second is a character: ‘p’ for the circle suit, ‘s’ for the bamboo suit, and ‘m’ for the character suit.
  • For Honor tiles, the first is a integer: from one to seven stands for East, South, West, North, White, Green, and Red respectively. The second one is always ‘z’.

We promise that the input is a legal hand, which means there isn’t another type of tiles described above or there are more than four same tiles.

Output

For each case, if the hand is Seven Pairs, output “Seven Pairs”. If the hand is Thirteen Orphans, output “Thirteen Orphans”. If the hand is neither Seven Pairs nor Thirteen Orphans, output “Neither!”.

Sample Input

Sample Output

题目大意:给你一个麻将序列 问你这个序列是不是SevenPairs或者 Thirteen Orphans 还有可能都不是

这题是很明显的水题 。。。建立一个结构体把牌排下序,然后判断一下就可以了 只有判断的时候有一点点技巧

技巧看代码就能看懂 就不解释了 = =

代码: