The Link Your Class | https://bbs.csdn.net/forums/MUEE308FZU202201 |
---|---|
The Link of Requirement of This Assignment | https://bbs.csdn.net/topics/608734907 |
The Aim of This Assignment | extract keywords |
MU STU ID and FZU STU ID | 20123345_832002112 |
repository
commit
PSP table
PSP | Content of the task | Time to plan for completion (min) | Actual completion time (min) |
---|---|---|---|
Planning | plan | 30 | 10 |
Estimate | Estimate how much time the task will take and map out the steps | 10 | 5 |
Development | The process of developing software | - | - |
Analysis | Requirements analysis (including learning new technology) | 30 | 20 |
Design Spec | Generating design Documents | - | - |
Design Review | Design review | - | - |
Coding Standard | Code specification (appropriate specification for current development) | 10 | 20 |
Design | The specific design | 60 | 45 |
Coding | Specific coding | 500 | 800 |
Code Review | Code review | 60 | 30 |
test | Testing (self-testing, modifying code, submitting changes) | 400 | 500 |
Test Report | Test results are reported and analyzed | 20 | 20 |
Size Measurement | Calculation of effort | 5 | 5 |
Postmortem & Process Improvement Plan | Summarize afterwards and propose the process improvement plan | 60 | 60 |
Summary | conclusion | 1185 | 1515 |
Procedure
The process of solving the problem
- first need to know how to read the file and read the contents of the file
- After reading the contents of the file, you need to know how to divide the keywords. Fortunately, the test file only contains the key fields of switch, if-else and case, so you don’t need to consider so many cases. After these keywords structure division, and statistics of the number of occurrences
- According to the document from the basic to progressive development, the first development of simple data reading function, can enhance the expansion, write all the keywords into an array, and then each time from the array for two-dimensional search, find the corresponding keywords, and then count the number. This section only contains some keywords. The range of a keyword is judged by the position of the parentheses and the beginning, end and end symbol of the keyword
flow chart
the switchcase
the if else
main code
count all num
string Count_Key_Num(const string& str) {
int start_index = 0, end_index;;
string NewStr = DeleMuch(str);
end_index = NewStr.length();
BinSearch(start_index, end_index, NewStr);
regex z("else if");
NewStr = regex_replace(NewStr, z, "elseif");
for (int i = 0; i < KeyNum; i++)
{
if (key[i].num != 0)
{
TotalNum += key[i].num;
// cout << key[i].word << " num: " << key[i].num << endl;
}
}
cout << "total num: " << TotalNum << endl;
// cout << NewStr << endl;
return NewStr;
}
count switch case
string Count_SwiCase_Num(const string& str) {
string NewStr = Count_Key_Num(str);
int len = NewStr.length(), index = 0, cnt;
stack<int> IdxStack;
while ((index = NewStr.find("switch", index)) < len && (index != -1))
{
IdxStack.push(index);
index++;
// cout << "index:" << index << endl;
}
printf("switch num: %d\n", key[SwitchIdx].num);
printf("case num:");
vector<int> CaseNum;
while (!IdxStack.empty())
{
cnt = 0, index = IdxStack.top() + 5;
while ((index = NewStr.find("case", index)) < len && (index != -1))
{
cnt++;
index++;
}
len = IdxStack.top();
IdxStack.pop();
CaseNum.push_back(cnt);
}
for (int i = CaseNum.size() - 1; i >= 0; i--)
{
printf(" %d", CaseNum[i]);
}
putchar('\n');
return NewStr;
}
count if-else
void Count_IfEls_Num(const string& str, int level) {
string NewStr = Count_SwiCase_Num(str);
string wd;
stack<string> IfStack;
int len = NewStr.length();
if (isalpha(NewStr[0]))
{
wd += NewStr[0];
}
for (int i = 1; i < len; i++)
{
if (isalpha(NewStr[i]))
{
wd += NewStr[i];
}
else if (isalpha(NewStr[i - 1]) && !isalpha(NewStr[i]))
{
// 遇到 if elseif 入栈,遇到 else 出栈并根据情况计数
if (wd == "if" || wd == "elseif")
{
IfStack.push(wd);
}
else if (wd == "else")
{
if (IfStack.top() == "elseif")
{
ElsIfNum++;
while (IfStack.top() == "elseif")
{
IfStack.pop();
}
}
else
{
IfElsNum++;
}
IfStack.pop();
}
wd = "";
}
}
cout << "if-else num: " << IfElsNum << endl;
if (level == 4)
{
cout << "if-elseif-else num: " << ElsIfNum << endl;
}
return;
}
Performance optimization
test screenshots
conclusion
-
By this section experiments, I realized that the difference in plan and actual, before I started to think, for example, when writing the ifelse judgment part is more complex, it takes me most of the time, but when I actually perform, I find the most time consuming part is actually build the whole project of the overall planning process, if a project in the early stage of the plan is perfect, The follow-up work will be clearer and less time-consuming.
-
I think it’s important to refer to other people’s code, and I refer to other people’s code in my own code. In the stack processing logic, originally wanted to implement through the array, but met some logic problems have been unable to solve, after searching the results of the Internet found that this method is very easy to use
-
For the writing part of the blog, I think it looks very simple, but it is very complicated to write, took a lot of time, almost today I have been writing this. As you write, you’ll need to keep reviewing your code, and you’ll probably find new bugs. At the same time, I also need to learn new knowledge, such as how to draw a flow chart with Markdown, although this time it is not very good. I think the process of writing a blog is to re-connect the various parts of this homework, which is equal to re-warming the whole process of doing homework. To sum up, this difficulty needs enough time to be solved