-
Notifications
You must be signed in to change notification settings - Fork 23
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
Showing
5 changed files
with
196 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,51 @@ | ||
/* 成绩排序 */ | ||
|
||
#include <iostream> | ||
#include <algorithm> | ||
using namespace std; | ||
|
||
struct student{ | ||
int num; | ||
string name; | ||
int score; | ||
}; | ||
|
||
bool cmp1(student s1, student s2) | ||
{ | ||
if(s1.score == s2.score) return s1.num < s2.num; | ||
return s1.score > s2.score; | ||
} | ||
|
||
bool cmp2(student s1, student s2) | ||
{ | ||
if(s1.score == s2.score) return s1.num < s2.num; | ||
return s1.score < s2.score; | ||
} | ||
|
||
int main() | ||
{ | ||
int n, m; | ||
string s; | ||
student st[1000]; | ||
while(cin >> n >> m) | ||
{ | ||
getchar(); | ||
for(int i = 0; i < n; i++) | ||
{ | ||
getline(cin, s); | ||
int f = s.find(' '); | ||
st[i].num = i; | ||
st[i].name = s.substr(0, f); | ||
st[i].score = stoi(s.substr(f+1)); | ||
} | ||
if(m) | ||
sort(st, st+n, cmp2); | ||
else | ||
sort(st, st+n, cmp1); | ||
for(int i = 0; i < n; i++) | ||
{ | ||
cout << st[i].name << ' ' << st[i].score << endl; | ||
} | ||
} | ||
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,42 @@ | ||
/* 矩阵乘法计算量估算 */ | ||
|
||
#include <iostream> | ||
#include <vector> | ||
#include <stack> | ||
#include <map> | ||
using namespace std; | ||
|
||
int main() | ||
{ | ||
int n, a, b; | ||
string s; | ||
while(cin >> n) | ||
{ | ||
int cnt = 0; | ||
vector<pair<int, int> > v; | ||
stack<pair<int, int> > st; | ||
for(int i = 0; i < n; i++) | ||
{ | ||
cin >> a >> b; | ||
v.push_back(make_pair(a, b)); | ||
} | ||
getchar(); | ||
getline(cin, s); | ||
for(int i = 0, j = 0; i < s.size(); i++) | ||
{ | ||
if (s[i] != '(' && s[i] != ')') { | ||
st.push(v[j++]); | ||
} else if(s[i] == ')') { | ||
if(st.size() == 1) break; //测试用例中出现了括号不匹配的例子。 | ||
pair<int, int> p1 = st.top(); | ||
st.pop(); | ||
pair<int, int> p2 = st.top(); | ||
st.pop(); | ||
st.push(make_pair(p2.first, p1.second)); | ||
cnt += p2.first * p1.first * p1.second; | ||
} | ||
} | ||
cout << cnt << endl; | ||
} | ||
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,43 @@ | ||
/* 字符串通配符 */ | ||
|
||
#include <iostream> | ||
using namespace std; | ||
|
||
bool match(string a, string b) | ||
{ | ||
// 可以做一下剪枝 | ||
for(int i = 0, j = 0; i < a.size(); i++, j++) | ||
{ | ||
if (a[i] == '*') { | ||
bool f = false; | ||
string s = a.substr(i+1); | ||
for (int k = j; k < b.size(); k++) | ||
{ | ||
f = f || match(s, b.substr(k)); | ||
} | ||
return f; | ||
} | ||
else if (a[i] == '?') { | ||
continue; | ||
}else if (a[i] != b[j]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
int main() | ||
{ | ||
string a, b; | ||
while(getline(cin, a)) | ||
{ | ||
getline(cin, b); | ||
if (match(a, b)) { | ||
cout << "true" << endl; | ||
}else { | ||
cout << "false" << endl; | ||
} | ||
|
||
} | ||
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,29 @@ | ||
/* 百钱买百鸡问题 */ | ||
|
||
#include <iostream> | ||
using namespace std; | ||
|
||
void f() | ||
{ | ||
int x, y, z; | ||
for (x = 0; x <= 300/15; x++) | ||
{ | ||
y = (200 - 14 * x) / 8; | ||
z = 100 - x - (200 - 14 * x) / 8; | ||
if ((200 - 14 * x) % 8 == 0 && y >= 0) | ||
{ | ||
printf("%d %d %d\n", x, y, z); | ||
} | ||
} | ||
return ; | ||
} | ||
|
||
int main() | ||
{ | ||
int n; | ||
while(cin >> n) | ||
{ | ||
f(); | ||
} | ||
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,31 @@ | ||
/* 计算日期到天数转换 */ | ||
|
||
#include <iostream> | ||
using namespace std; | ||
|
||
int isLeap(int y) | ||
{ | ||
if(y%400 == 0) return 1; | ||
else if(y%100 && y%4 == 0) return 1; | ||
else return 0; | ||
} | ||
|
||
int main() | ||
{ | ||
int month[13] = {0,0,31,28,31,30,31,30,31,31,30,31,30}; | ||
for(int i = 1; i < 13; i++) | ||
{ | ||
month[i] += month[i-1]; | ||
} | ||
int y, m, d; | ||
while(cin >> y >> m >> d) | ||
{ | ||
int day = 0; | ||
if(m > 2) { | ||
day = isLeap(y); | ||
} | ||
day += month[m] + d; | ||
cout << day << endl; | ||
} | ||
return 0; | ||
} |