On-line written test technology synthesis direction of HKUST Xunfei: divided into java and C++, programming questions have three total of 60 points.
First: quarrel //20 points
Time limit: C/C++ language 2000MS; other languages 4000MS
Memory limitation: C/C++ language 65536KB; other languages 589824KB
Title Description:
There are n individuals in a queue, each of whom has a standing direction: left-facing or right-facing. Because everyone in this person hates other people, when two people stand face to face, they will have an argument, and then one of them will be kicked out of the queue. It is possible for anyone to be kicked out of the queue.
We use the character L to represent a left-facing person and the character R to represent a right-facing person. Then the queue can be described by a string. For example, RLLR means a queue of four people, the first and the second of whom stand face to face. When they quarrel, the queue may become LLR or RLR; if they become RLR, the first person will quarrel with the second person, and the queue will further become LR or RR.
If there may be a lot of quarrels at the same time, then only one of them will happen, and any one of them is possible.
You want to know how many people will be left in the queue after a series of arguments?
input
The first line contains a string of characters L and R.
1 < String Length < 105
sample input
LRRLRL
<div class="outputarea yangli ng-scope" ng-if="model.ques.questype==6 && model.ques.outputSample != null && model.ques.outputSample!=''" "="" style="box-sizing: border-box; margin: 0px; padding: 0px;">
sample output
2
Hint
One possible change is that: LRRLRL -> LRLRL -> LRRL -> LRL -> LRMy idea is: R is on the left, L is on the right, adjacent to eliminate any one, output by sample is discontinuous campus R and L, the last remaining number of letters is output.
The code is as follows
But the result of operation is not right. Seek a solution through the Great God's help.#include <stdio.h> #include <string.h> int main() { char str[10]; int i = 1; int n,j,Num_Remain; printf("Please Enter: \n"); gets(str); //printf("%s\n",str); Num_Remain = strlen(str); for(n = 0;str[n] != '\0';n++) { if((str[n] == 'R') && (str[n++] == 'L')) { if( i%2 ) { i++; for(j = n;str[j] != '\0';j++) str[j] = str[j++]; Num_Remain--; printf("%d",Num_Remain); n--; } else { i++; for(j = n + 1;str[j] != '\0';j++) str[j] = str[j++]; Num_Remain--; n--; } } } printf("%d",Num_Remain); return 0; }
Second course: Ball game//20 points
Time limit: C/C++ language 1000MS; other languages 3000MS
Memory limitation: C/C++ language 65536KB; other languages 589824KBTitle Description:
The College Football Association has decided to hold a national college football match. Each school sends a team to represent the school. The competition will be divided into several zones. In the final competition, no more than n teams will participate. After fierce competition, the team that has the chance to participate in the finals has been decided.
The association has adjusted the rules of the competition to make it more spectacular.
1. In the finals, there are n teams and n even teams.
2. Entering the top 1/2 team is eligible to enter the knockout tournament;
3. Teams are ranked according to points. The specific rules are: win a game, accumulate 3 points; draw a game, accumulate 1 point; and lose a game, accumulate 0 points. Teams are first arranged in descending order of points, with the same points in descending order of net winners and the same points in descending order of goals.
4. Based on the above rules, no ranking ambiguity has occurred.
With the progress of the schedule, the results of the various teams have been determined. Little B is responsible for determining the list of qualifying teams. She asks you for help. Can you help her?
input
There are many groups of test data. The first action of each group is an integer n (1=<n<=50), which is the number of teams participating in the finals. The names of the following teams are composed of no more than 30 upper and lower Latin letters. The subsequent n*(n-1)/2 behavioral events were carried out in the form of name1-name2 num1:num2, indicating the score of the two teams (0=<num1, num2<=100). Make sure that there are no two teams with the same name, and that there will be no teams playing their own games, and that each game only occurs once.
sample input
4
A
B
C
D
A-B 1:1
A-C 2:2
A-D 1:0
B-C 1:0
B-D 0:3
C-D 0:3
2
a
A
a-A 2:1
<div class="outputarea yangli ng-scope" ng-if="model.ques.questype==6 && model.ques.outputSample != null && model.ques.outputSample!=''" "="" style="box-sizing: border-box; margin: 0px; padding: 0px;">
sample output
A
D
a
The code is as follows
From the horse racing network, local debugging is no problem, to the online compiler correct rate of 0%.~~~#include<iostream> #include<vector> #include<algorithm> #include<string> #include<stdlib.h> using namespace std; bool myComp(const vector<int>& a, const vector<int>& b){ if(a[1]>b[1]) return true; else if(a[1]<b[1]) return false; if(a[2]>b[2]) return true; else if(a[2]<b[2]) return false; if(a[3]>b[3]) return true; else if(a[3]<b[3]) return false; else return true; } int main(void){ int n; while(cin>>n){ vector<string> names; vector<vector<int>> datas; for(int i = 0; i < n; i++){ vector<int> t; for(int j = 0; j < 4; j++){ t.push_back(0); } datas.push_back(t); } for(int i = 0; i < n; i++){ datas[i][0] = i; } for(int i = 0; i < n; i++){ string t; cin>>t; names.push_back(t); } for(int i = 0; i < n*(n-1)/2; i++){ string t; cin>>t; int ind = t.find('-'); string name1 = t.substr(0,ind); string name2 = t.substr(ind+1,t.size()-ind-1); auto iter = find(names.begin(),names.end(),name1); int team1 = iter-names.begin(); iter = find(names.begin(),names.end(),name2); int team2 = iter-names.begin(); cin>>t; ind = t.find(':'); string s1 = t.substr(0,ind); string s2 = t.substr(ind+1,t.size()-ind-1); int score1 = atoi(s1.c_str()); int score2 = atoi(s2.c_str()); if(score1 > score2){ datas[team1][1] += 3; } else if(score1 == score2){ datas[team1][1] += 1; datas[team2][1] += 1; } else{ datas[team2][1] += 3; } datas[team1][2] += (score1-score2)>0?(score1-score2):0; datas[team2][2] += (score2-score1)>0?(score2-score1):0; datas[team1][3] += score1; datas[team2][3] += score2; } sort(datas.begin(), datas.end(), myComp); vector<int> res; for(int i = 0; i < n/2; i++){ int team = datas[i][0]; res.push_back(team); } sort(res.begin(), res.end()); for(int i = 0; i < n/2; i++){ cout<<names[res[i]]<<endl; } } return 0; }Third: Course Selection Issues//20 Points
Time limit: C/C++ language 2000MS; other languages 4000MS
Memory limitation: C/C++ language 65536KB; other languages 589824KBTitle Description:
Xiao Ming is a student. He also comes to the school to choose courses. He wants to choose some courses to study. It is known that the courses are taught from Monday to Friday, 4 in the morning, 4 in the afternoon and 2 in the evening.
Xiao Ming is worried about the conflict in the time of choosing courses. So he wanted to check the course time.
input
Firstly, an integer n (0 < n <= 100) is input to indicate the total number of Xiaoming elective courses.
Then input n rows of course selection information, each row of course selection information has two numbers.
The first number indicates the opening time. The opening time is expressed in two digits. The first one represents Monday to Friday from 0 to 4, and the second one shows the order of lectures from morning to evening from 0 to 9, such as the third lecture on Tuesday from 12. 01 is the second lecture on Monday.
The second number in each line represents the course code, such as 204521. The course code is 6 digits. The input course code is not duplicated.
sample input
5
01 204521
23 204523
22 204526
01 204528
22 204527
<div class="outputarea yangli ng-scope" ng-if="model.ques.questype==6 && model.ques.outputSample != null && model.ques.outputSample!=''" "="" style="box-sizing: border-box; margin: 0px; padding: 0px;">
sample output
01 204521 204528
22 204526 204527
Hint
Input Sample 2 3 11 204521 23 204522 43 204531 Output Sample 2 YESThe code is as follows:From the horse racing net, for reference only#include<iostream> #include<string> #include<vector> using namespace std; struct stru{ string str; int course; int flag;//Whether to duplicate markers int fl;//Has the label been output? }; int main() { stru arr[100]; int n; cin>>n; int i,j; for(i=0;i<n;i++) { cin>>arr[i].str>>arr[i].course; arr[i].flag=0; arr[i].fl=0; } int count=0; for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(arr[i].str[0]==arr[j].str[0] && arr[i].str[1]==arr[j].str[1] ) { count=1; arr[i].flag=1; arr[j].flag=1; } } } if(count==0) { cout<<"YES"<<endl; return 0; } for(i=0;i<n;i++) { if(arr[i].flag==1 && arr[i].fl==0) { cout<<arr[i].str<<" "<<arr[i].course<<" "; for(j=0;j<n;j++) { if(i!=j && arr[i].str[0]==arr[j].str[0] && arr[i].str[1]==arr[j].str[1]) { arr[i].fl=1; arr[j].fl=1; cout<<arr[j].course<<" "; } } cout<<endl; } } return 0; }C language is still in the beginner stage. Keep improving. Technical support engineers also require good programming skills.~~~Come on, everybody.~