当前位置:网站首页>CCF command line options (Full Score code + problem solving ideas + skill summary) March 3, 2014
CCF command line options (Full Score code + problem solving ideas + skill summary) March 3, 2014
2022-06-30 14:40:00 【A cute little monkey】
Title Description

Their thinking
- The title describes the options to output in ascending order in lowercase letters , So you can Store answers in string Array in , If the letter is an option , The output , If it is a parameterized option , Then the parameters are also output ,ans Array storage parameters
- There are two options , So first read the first line of format string into , Determine whether each letter has a reference , use Two Boolean arrays to store whether the letter has a parameter
- For the convenience of string storage , First utilize getline() Read the string contents of one line
- Again utilize stringstream Store the read one line string hierarchically in... According to the spaces vector Array in
- Then judge according to the read content , There are three situations : No parameter option (ans[i] Store something at will ), It is a parameterized option (ans[i] Store the next row of the array ), Other irregularities stop parsing
- According to the ans Array to output the answer , Any options that appear on the command line , Its ans.size() It's not zero , Output option name , If it is an option with parameters , And output ans
Code implementation
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <sstream>
using namespace std;
const int N = 30;
bool op1[N], op2[N]; //op1 Store parameterless options ,op2 Parameter options are stored
int n;
string ans[N];
int main()
{
string str;
cin >> str; // Read in all the parameters
for (int i = 0; i < str.size(); i ++) // Analyze whether the parameter has a parameter
{
if (i + 1 < str.size() && str[i + 1] == ':') // If the next person doesn't cross the line , And the next digit is a colon , Then this bit is a parameterized option
{
op2[str[i] - 'a'] = true; // indicate str[i] It is a parameterized option
i ++; // Skip colon
}
else
{
op1[str[i] - 'a'] = true;// indicate str[i] Is an option without parameters
}
}
cin >> n;
getchar();// Filter return
for (int C = 1; C <= n; C ++)
{
printf("Case %d:", C);
getline(cin, str); // Reading the entire line requires getline, Use getline( If the last read in used cin) You need to filter the carriage return in the previous line
stringstream ssin(str);
vector <string> ops;
while(ssin >> str) ops.push_back(str);// take str Stored hierarchically in an array by spaces
for (int i = 0; i < 26; i ++) ans[i].clear();// take ans Empty
for (int i = 1; i < ops.size(); i ++) // The first is the name , skip
{
if (ops[i][0] != '-' || ops[i][1] < 'a' || ops[i].size() != 2) break;
int k = ops[i][1] - 'a';
if(op1[k])
{
ans[k] = '*';
}
else if(op2[k] && i + 1 < ops.size())
{
ans[k] = ops[i + 1];
i ++;
}
else break;
}
for (int i = 0; i < 26; i ++)
{
if(ans[i].size())
{
cout << " -" << char('a' + i);
if(op2[i])
{
cout << ' ' << ans[i];
}
}
}
cout << endl;
}
return 0;
}
Skill summary
- Simulation questions are mainly Think about how to store ( Storage solves 80% of the problem )
- A string of Selection of access mode Very important
- stringstream and vector And other common functions should be used skillfully ( The combination of the two can be Strings are stored hierarchically according to spaces )
- string Array From the subscript 0 Start storage
- Empty string Using an array clear function
- Use words skillfully Parent subscript mapping Methods
边栏推荐
- 2021-08-07 native and package types
- ThinkPHP show method parameter controllable command execution
- DiceCTF - knock-knock
- How does hbuilder display in columns?
- On simple code crawling Youdao translation_ 0's problem (to be solved)
- In situ merging of two arrays with two pointers
- Summary of use of laravel DCAT admin
- PHP reverses scenarios based on code and skillfully uses debug_ backtrace()
- Project management - common English vocabulary I
- Implementation of forwarding server using IO multiplexing
猜你喜欢

Error on datetime when importing SQL file from MySQL

XSS challenge (1-5) more detailed answers

Upgrade centos7 mysql5.5 to mysql5.7 non RPM in the form of tar package

Notes on reverse learning in the first week of winter vacation

DefCamp Capture the Flag (D-CTF) 2021-22 web

About the problems encountered when using the timer class to stop with a button (why does the QPushButton (for the first time) need to be clicked twice to respond?)

Clear the route cache in Vue

val_ Loss decreases first and then increases or does not decrease but only increases
![[buuctf] [actf2020 freshman competition]include](/img/42/50439290177fdea5f431e315cac1a1.jpg)
[buuctf] [actf2020 freshman competition]include

Geoffreyhinton: my 50 years of in-depth study and Research on mental skills
随机推荐
[extensive reading of papers] a delicious recipe analysis framework for exploring multi modal recipes with variable attributes
Initial attack and defense world Misc
Lihongyi machine learning 2020 homework summary
@component使用案例
[extensive reading of papers] attributes guided facial image completion
The JSON data returned from the control layer to JS has a "\" translator. How to remove it
Laravel upload error
Pit used by go language array type
How to use Alibaba Vector Icon
@Component use cases
Computer screenshot how to cut the mouse in
KnightCTF WEB
XSS challenge (6-10) more detailed answers
Calculates the length of the last word in a string, separated by spaces
Advanced usage of go language for loop break and continue
PS cutting height 1px, Y-axis tiling background image problem
Mysql database foundation: stored procedures and functions
Why does the folder appear open in another program
JS array sorting method summary
JS time conversion standard format, timestamp conversion standard format