Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- string s;
- cout << "Nhap s: "; getline(cin, s);
- // task_a
- while (s[0] == ' ') s.erase(0, 1);
- while (s[s.size() - 1] == ' ') s.erase(s.size() - 1, 1);
- while (s.find(" ") != -1) {
- int vt = s.find(" ");
- s.erase(vt, 1);
- }
- cout << "Ket qua: " << s << endl;
- // task_b
- int tu = 1;
- for (int i = 0; i < s.size(); i++) {
- if (s[i] == ' ') tu++;
- }
- cout << "So tu: " << tu << endl;
- // task_c
- string dau, cuoi;
- for (int i = 0; i < s.size(); i++) {
- if (s[i] == ' ') break;
- dau += s[i];
- }
- for (int i = s.size() - 1; i >= 0; i--) {
- if (s[i] == ' ') break;
- cuoi = s[i] + cuoi;
- }
- cout << "Tu dau: " << dau << endl;
- cout << "Tu cuoi: " << cuoi << endl;
- // task_d
- bool dx = 1;
- for (int i = 0; i < s.size(); i++) {
- if (s[i] != s[s.size() - 1 - i]) dx = 0;
- }
- if (dx) cout << "s la xau doi xung" << endl;
- else cout << "s khong la xau doi xung" << endl;
- // task_e
- while (s.find("anh") != -1) {
- int vt = s.find("anh");
- s.erase(vt, 3);
- s.insert(vt, "em");
- }
- cout << "Ket qua: " << s << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment