当前位置:网站首页>CCF string matching (Full Score code + problem solving ideas + skill summary) March 3, 2014
CCF string matching (Full Score code + problem solving ideas + skill summary) March 3, 2014
2022-06-30 14:41:00 【A cute little monkey】
Skill summary
This topic mainly examines the string related operations
// String lookup
//1. Method 1 :find() function ———— The time complexity is the product of two string lengths
string a = "abcde";
string b = "ab";
cout << a.find(b) // Output Zero , The first subscript position of the string
//2. Method 2 :strstr() function ———— The time complexity is linear , and kmp Time complexity is almost
char father[N];
char son[N];
cin >> father;
cin >> son;
char * res = strstr(father, son); // Look for your son in your father
if(res == NULL) // No return found null
printf(" Can't find ");
else // If you find , Returns the position of the first occurrence of the string in the main string and the subsequent string ;strstr(abcdef, bc) Result tail bcdef
printf("%s", res);
// String case conversion
// Use transform function
#include <algorithm>
string a;
transform(a.begin(), a.end(),a.begin(),::tolower); //toupper Is to make characters uppercase
Title Description

Their thinking
- The data range is small , utilize find Function search time complexity n*2, No timeout
- Case sensitive is direct find, Case insensitive, the string and query string are unified into upper case or lower case, and then find Find whether the substring exists
Code implementation
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
string s;
bool flag;
int n;
//strstr and kmp Almost efficient ,0(n);
int main()
{
cin >> s;
cin >> flag;
cin >> n;
if (!flag)
{
transform(s.begin(),s.end(),s.begin(),::tolower);
}
while (n --)
{
string a;
string res;
cin >> a;
res = a;
if (!flag) transform(a.begin(), a.end(), a.begin(), ::tolower);
if(a.find(s) != -1) //find It's case sensitive , If found, the initial subscript position of the string will be returned , Time complexity 0(n * m)
{
cout << res << endl;
}
}
return 0;
}
边栏推荐
- 2021-07-15Caused by: org. quartz. ObjectAlreadyExistsException: Unable to store Job : ‘DEFAULT. TASK_ 1‘
- Alipay certificate mode payment interface
- On simple code crawling Youdao translation_ 0's problem (to be solved)
- DB2 SQL Error: SQLCODE=-206, SQLSTATE=42703
- Using docker to manage MySQL services under Windows
- Detailed explanation of settimeout() and setinterval()
- ot initialized – call ‘refresh’ before invoking lifecycle methods via the context: Root WebApplicati
- go channel && select
- Lost connection to the flow server (0 retries remaining): |Out of retries, exiting! Error reporting solution (flow)
- Use of laravel repository mode
猜你喜欢

Problems in QT creator (additional unknown and error lines are listed in the debug output window)

2021-05-12

remote: Support for password authentication was removed on August 13, 2021. Please use a personal ac

Notes on reverse learning in the first week of winter vacation

Laravel configures passport and returns token using JWT

I love network security for new recruitment assessment

After the MySQL service on the local computer is started and stopped, some services will automatically stop when they are not used by other services or programs

Detailed explanation of the first three passes of upload Labs

KnightCTF WEB

val_ Loss decreases first and then increases or does not decrease but only increases
随机推荐
@Component use cases
JS to realize simple lottery function
DiceCTF - knock-knock
Thoughts on the security of a PHP file name regular verification
Invalid argument during startup: Failed to open the . conf file: redis-window
The first dark spring cup dnuictf
Cost forecast of PMP (BAC, EAC, etc)
Go sync. WaitGroup
[geek challenge 2019] PHP problem solving record
An error is reported when installing dataspherestudio doc: invalid default value for 'update_ time‘
Four isolation levels of MySQL
How does hbuilder display in columns?
Thinkphp5 log file contains trick
The kth largest element in the sorted array
Lfi-rce without controllable documents
Problem: wechat developer tool visitor mode cannot use this function
DB2 SQL Error: SQLCODE=-206, SQLSTATE=42703
Greedy two-dimensional array sorting
Detailed explanation of the first three passes of upload Labs
数据恢复软件EasyRecovery15下载