-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
182e927
commit 4b9a8e9
Showing
6 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <iostream> | ||
#include <string> | ||
|
||
using namespace std; | ||
|
||
int main(){ | ||
string s; | ||
cout << "Nhap xau ki tu: "; | ||
getline(cin,s); | ||
int count=0; | ||
for (int i=0;i<s.length();i++){ | ||
if (s[i]>='a' && s[i]<='z'){ | ||
count++; | ||
} | ||
} | ||
cout << "Xau vua nhap co " << count << " chu cai thuong.\n"; | ||
for (int i=0;i<s.length();i++){ | ||
if (s[i]=='a'){ | ||
s.erase(i,1); | ||
i--; | ||
} | ||
} | ||
cout << "Xau sau khi xoa moi ki tu 'a' la: " << s << "\n"; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include <iostream> | ||
#include <string> | ||
|
||
using namespace std; | ||
|
||
int main(){ | ||
string s; | ||
cout << "Nhap xau ki tu: "; | ||
getline(cin,s); | ||
bool ans=true; | ||
int n=s.length(),words=1; | ||
for (int i=0;i<n-1;i++){ | ||
if (s[i]==' ' && s[i+1]==' '){ | ||
ans=false; | ||
break; | ||
} | ||
if (s[i]==' ' && s[i+1]!=' '){ | ||
words++; | ||
if (words>10){ | ||
ans=false; | ||
break; | ||
} | ||
} | ||
} | ||
if (ans==true) cout << "Xau tren hop le.\n"; | ||
else cout << "Xau tren khong hop le.\n"; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <iostream> | ||
#include <string> | ||
|
||
using namespace std; | ||
|
||
int main(){ | ||
string s; | ||
cout << "Nhap xau ki tu: "; | ||
getline(cin,s); | ||
char c; | ||
cout << "Nhap ki tu c: "; | ||
cin >> c; | ||
int k; | ||
cout << "Nhap so nguyen k: "; | ||
cin >> k; | ||
s.insert(k,1,c); | ||
cout << "Xau sau khi chen them ki tu " << c << " vao vi tri " << k << " la: " << s << "\n"; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include <iostream> | ||
#include <stack> | ||
#include <string> | ||
|
||
using namespace std; | ||
|
||
bool arePair(char opening,char closing){ | ||
if (opening == '(' && closing == ')') return true; | ||
else if (opening == '{' && closing == '}') return true; | ||
else if (opening == '[' && closing == ']') return true; | ||
return false; | ||
} | ||
|
||
bool balanced(string str){ | ||
stack <char> S; | ||
for (int i=0;i<str.length();i++){ | ||
if(str[i] == '(' || str[i] == '{' || str[i] == '[') | ||
S.push(str[i]); | ||
else if(str[i] == ')' || str[i] == '}' || str[i] == ']'){ | ||
if (S.empty() || !arePair(S.top(),str[i])) | ||
return false; | ||
else | ||
S.pop(); | ||
} | ||
} | ||
return S.empty() ? true:false; | ||
} | ||
|
||
int main(){ | ||
string s; | ||
cout << "Nhap xau dau ngoac: "; | ||
cin >> s; | ||
if (balanced(s)) | ||
cout << "Hop le.\n"; | ||
else | ||
cout << "Khong hop le.\n"; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <iostream> | ||
#include <stdlib.h> | ||
|
||
using namespace std; | ||
|
||
int main(){ | ||
int n; | ||
cout << "Nhap so phan tu cua mang: "; | ||
cin >> n; | ||
int *a=new int[n]; | ||
for (int i=0;i<n;i++){ | ||
cout << "Nhap phan tu thu " << i+1 << " cua mang: "; | ||
cin >> *(a+i); | ||
} | ||
int k=n; | ||
for (int i=0;i<n;i++){ | ||
if (*(a+i)%2!=0){ | ||
k++; | ||
a=(int*) realloc(a,k*sizeof(int)); | ||
*(a+k-1)=*(a+i); | ||
} | ||
} | ||
n=k; | ||
cout << "Mang sau khi sao chep cac phan tu le vao cuoi la:\n"; | ||
for (int i=0;i<n;i++){ | ||
cout << *(a+i) << " "; | ||
} | ||
cout << "\n"; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <iostream> | ||
#include <stdlib.h> | ||
|
||
using namespace std; | ||
|
||
int main(){ | ||
int n; | ||
cout << "Nhap so phan tu cua mang: "; | ||
cin >> n; | ||
int *a; | ||
a = new int[n]; | ||
for (int i=0;i<n;i++){ | ||
cout << "Nhap phan tu thu " << i+1 << " cua mang: "; | ||
cin >> *(a+i); | ||
} | ||
|
||
for (int i=0;i<n;i++){ | ||
if (*(a+i)%2==0){ | ||
n--; | ||
for (int j=i;j<n;j++){ | ||
*(a+j)=*(a+j+1); | ||
} | ||
a = (int*) realloc(a,n*sizeof(int)); | ||
i--; | ||
} | ||
} | ||
|
||
cout << "Mang sau khi xoa het cac phan tu chan la:\n"; | ||
for (int i=0;i<n;i++){ | ||
cout << *(a+i) << " "; | ||
} | ||
cout << "\n"; | ||
return 0; | ||
} |