In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article focuses on "what is the core code pattern and ACM pattern", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what is the core code pattern and ACM pattern"!
What is the ACM input mode? Is to construct their own input data format, to deal with the container filled, OJ will not give you any code, including include which functions have to write their own, and finally have to control the format of the returned data.
On the other hand, the force buckle is the core code pattern, that is, all the data to be processed has been put into the container, and the logic can be written directly, for example:
Class Solution {public: int minimumTotal (vector& triangle) {}}
If you learn the algorithm from the beginning has been on the button, then suddenly cut to the cattle on the ACM mode will not be very suitable.
Because I worked on ACM when I was at school, and I brushed 6 or 700 questions on POJ (the online problem judging system of Peking University) and ZOJ (the online problem judging system of Zhejiang University), I was very familiar with this ACM model.
Next, I'll tell you how to write the ACM pattern.
Here I take Niu Ke on Tencent 2020 campus recruitment-background interview questions to give an example, I do not explain the idea of this question, but take this question as an example to explain the ACM input and output format.
Topic description:
Because of the excellent performance, the company gave Xiao Q n days off. As a workaholic, Xiao Q planned to work, exercise or rest during the holiday. He has a strange habit of not working or exercising for two days in a row. Only when the company is open, Xiao Q can go to work, only when the gym is open, Xiao Q can go to the gym, Xiao Q can only do one thing a day. Give the business situation of the company and gym during the holiday, and ask Xiao Q to take at least a few days off.
Enter a description:
An integer in the first line indicates the number of days off
The number of n in the second row is 0 or 1 each, and the I number indicates whether the company is open on the I day.
The number of n in the third row is 0 or 1 each, and the I number indicates whether the gym is open on the I day.
(1 for business 0 for closed business)
Output description:
An integer indicating the minimum number of days for Xiao Q to rest
Example 1:
Enter:
four
1 1 0 0
0 1 1 0
Output:
two
If this question is to be the core code mode on the force button, OJ should directly give the following code:
Class Solution {public: int getDays (vector& work, vector& gym) {/ / processing logic}}
In the above code, we just write the core logic directly. Work array and gym array are filled out and used directly. After processing, the return result is finished.
So let's take a look at the ACM mode. How do we write it?
The ACM pattern requires that the written code can be run locally, so we need to write which library functions of include, construct input use cases, and construct output use cases.
For example, in order for the code to run, you need to include these library functions:
# include # include using namespace std
Then start to write the main function to deal with the input use case, example one is a complete test case, generally we tested a use case and also tested the second use case, so use: while (cin > > n) to enter data.
The n entered here is the number of days, and after you get the number of days, you can construct the work array and the gym array.
At this point, the input use case construction has been completed, then the processing logic is completed, and the result is returned.
The complete code is as follows:
# include # include using namespace std; int main () {int n; while (cin > > n) {vector gym (n); vector work (n); for (int I = 0; I
< n; i++) cin >> work [I]; for (int I = 0; I)
< n; i++) cin >> gym [I]; int result = 0; / / processing logic cout
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 240
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.