Baidu Programming Competition

Source: Internet
Author: User

Question 1 (100 points in total): continuous positive integer (10 points)

Description: a positive integer may be expressed as the sum of n (n> = 2) continuous positive integers, for example:
15 = 1 + 2 + 3 + 4 + 5
15 = 4 + 5 + 6
15 = 7 + 8
Write a program to find all consecutive positive integer sequences that meet the input positive integer
. Input data: A Positive Integer provided to the program as a command line parameter. Output Data: Standard Input
Print out all positive integer sequences that match the topic description. Each sequence has one sequence per row, and each sequence has the smallest
Start with a positive integer and print it in ascending order. If there are multiple sequences in the result, the smallest positive integer of each sequence is large.
Print the sequences from small to large. In addition, the sequence cannot be repeated. integers in the sequence are separated by a space. If no
There is a sequence that meets the requirements, and the output is "NONE ".
For example, for 15, the output result is:
1 2 3 4 5
4 5 6
7 8
For 16, the output result is:
None
Rating criteria: whether the program output result is correct.

The first code I wrote myself:

// Baidu. cpp: defines the entry point of the console application.
//

# Include "stdafx. H"
# Include <cmath>
Using namespace STD;

Int main (INT argc, _ tchar * argv [])
{
For (INT z = 1; Z <100; Z ++)
{
Int max = (INT) Ceil (z * 1.0)/2 );
Bool flag = false;
Cout <z <Endl;
For (INT y = 1; y <= max; y ++)
{
For (INT x = 1; x <Y; X ++)
{
If (x + y) * (Y-x + 1)/2 = z)
{
Flag = true;
For (INT I = x; I <= y; I ++)
{
Cout <I <"";
}
Cout <Endl;
}
}
}
If (! Flag)
{
Cout <"NONE" <Endl;
}
}
Cin> argc;
Return 0;
}

Question 2 (100 points for all four questions): size of the overlap interval (20 points)

Description: write a program to find the maximum value in the input data file described in "input data and format" below.
The size of the overlap interval.
For a positive integer N, if n is between two positive integers (assumed as a and B) in a row in the data file, that is, a <= N
<= B or a> = n> = B, then n belongs to the row. If n belongs to both I and J, there is an overlap between I and j.
Small is the number of integers that belong to both row I and J.
For example, the overlapping ranges of rows (10 20) and (12 25) are [12 20], and the size is 9; rows (20 10) and (
12 18) the overlap interval is [10 12], and its size is 3; the overlap interval of rows (20 10) and (20 30) is 1.
Input data: The program reads the input data text file named input.txt. The number of lines of the file is between 1 and 1.
, Between 000,000, each line uses a space to separate two positive integers, The Size order of the two positive integers is random, each
The number is between 1 and 2 ^ 32-1. You can download the input.txt file.
Use input files with different content .) Output Data: print out the maximum number of overlapping input data files on the standard output.
The size of the interval. If no rows overlap, 0 is output. Scoring standard: The program output result must be positive.
Indeed, the memory usage must not exceed 256 MB. The faster the program runs, the better.

Question 3 (100 points for all four questions): String replacement (30 points)

Description: write a program to replace the string in a text with another word based on the specified correspondence.
String. Input data: The program reads two input data text files named text.txtand dict.txt.
Text.txt is a large serial number containing Chinese characters, and dict.txt is separated by whitespace.
It is another text (including Chinese) that represents the correspondence between string (S1) and string (S2), which is about 10 thousand rows left
Right, two strings (S1 and S2) in each row, separated by one/T or space. S1 of each row in dict.txt is not sorted
And there may be duplicates. In this case, the S2. In text.txtand dict.txt
Each string may contain any character except whitespace. The string in text.txt must be the same as that in dict. T.
Only S1 in XT can be replaced. You can download the text.txtand dict.txt files.
In actual operation, we will use input files with different content .) Output Data: Print text on the standard output.
The entire text after txtis replaced by dict.txt. Scoring standard: The program output result must be correct, and the memory usage is higher.
The sooner the program runs, the better.

Question 4 (100 points in total): Low Frequency Word filtering (40 points)

Topic Description: write a program to delete words with the least number of occurrences from texts containing a large number of words. If there are many
The minimum number of times each word appears. Input data: The program reads data named cor.
Pus.txt is a large text file containing English words and Chinese words.
Or multiple whitespaces are separated. You can download the test corpus.txt file.
Will use different content input files .) Output Data: The data displayed in corpus.txt is printed on the standard output.
Text after words with the least number of times (words and words are in the original order and are still separated by spaces ). Rating criteria:
The program output result must be correct. The smaller the memory usage, the better the execution time of the program.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.