-
Notifications
You must be signed in to change notification settings - Fork 0
/
test31.cpp
34 lines (30 loc) · 893 Bytes
/
test31.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<algorithm>
#include<ctype.h>
#include<stdio.h>
using namespace std;
bool check_string(string s) {
size_t ampersand_pos = s.find('&');
size_t dollar_pos = s.find('$');
if (ampersand_pos == string::npos || dollar_pos == string::npos) {
return false;
}
string w = s.substr(0, ampersand_pos);
string m = s.substr(ampersand_pos + 1, dollar_pos - ampersand_pos - 1);
reverse(m.begin(), m.end());
return w == m;
}
int main()
{
string a = "asdf&fdsa$";
string ans = check_string(a) == true? "true": "false";
cout << a << " " << ans << endl;
a = "1234&4321$";
ans = check_string(a) == true ? "true" : "false";
cout << a << " " << ans << endl;
a = "12345&4321$";
ans = check_string(a) == true ? "true" : "false";
cout << a << " " << ans << endl;
}