7-1 考试周 (5point(s))
Submission
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int a, b; cin >> a >> b;
cout << a << "/";
cout << std::setprecision(1) << fixed << double(a) / b;
cout << "=" << b;
}
7-2 真的恭喜你 (10point(s))
Submission
#include <iostream>
using namespace std;
int main() {
int mark; cin >> mark;
if(mark >= 90) cout << "gong xi ni kao le " << mark << " fen!";
else cout << "kao le " << mark << " fen bie xie qi!";
return 0;
}
7-3 平均成绩 (10point(s))
Submission
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int n; cin >> n;
int boy = 0, girl = 0;
int boy_count = 0, girl_count = 0;
while(n--) {
int sex, mark;
cin >> sex >> mark;
if(sex == 0) {
girl_count++;
girl += mark;
} else {
boy_count++;
boy += mark;
}
}
cout << setprecision(1) << fixed << (girl + boy) / double(girl_count + boy_count) << " ";
if(boy_count) cout << setprecision(1) << fixed << boy / double(boy_count) << " ";
else cout << "X ";
if(girl_count) cout << setprecision(1) << fixed << girl / double(girl_count);
else cout << "X";
return 0;
}
7-4 古风A+B (15point(s))
Submission
#include <iostream>
#include <vector>
using namespace std;
int main() {
int a, b; cin >> a >> b;
int s = a + b;
if(s == 0) {
cout << 0;
return 0;
}
if(s < 0) {
cout << "-\n";
s = -s;
}
vector<int> res;
for(; s > 0; s /= 10) {
res.push_back(s % 10);
}
for(int i = res.size() - 1; i >= 0; --i) {
cout << res[i] << endl;
}
return 0;
}
7-5 猜近似数字 (15point(s))
Submission
#include <iostream>
using namespace std;
bool solve(string& target, string& guess)
{
bool onetime = false;
if(target.size() != guess.size()) return false;
for(int i = 0; i < target.size(); ++i) {
if(guess[i] != target[i]) {
if(guess[i] == target[i] - 1 || guess[i] == target[i] + 1) {
if(onetime) return false;
onetime = true;
} else {
return false;
}
}
}
return true;
}
int main() {
string t; cin >> t;
string g;
while(cin >> g) {
if(g == "-1") break;
solve(t, g) ? cout << "Yes" : cout << "No";
cout << endl;
}
return 0;
}
7-6 随机输一次 (20point(s))
Submission
#include <iostream>
#include <vector>
using namespace std;
const string chuizi = "ChuiZi";
const string jiandao = "JianDao";
const string bu = "Bu";
string lose(string in)
{
if(in == chuizi) return jiandao;
if(in == jiandao) return bu;
if(in == bu) return chuizi;
}
string win(string in)
{
if(in == chuizi) return bu;
if(in == bu) return jiandao;
if(in == jiandao) return chuizi;
}
int main() {
int t; cin >> t;
vector<int> r(t);
for(int i = 0; i < t; ++i) {
cin >> r[i];
}
string in;
int pointer = 0;
int count = 0;
while(cin >> in) {
if(in == "End") break;
count++;
if(count > r[pointer]) {
cout << lose(in);
count = 0;
pointer = (pointer + 1) % t;
} else cout << win(in);
cout << endl;
}
return 0;
}
7-7 阶乘的非零尾数 (20point(s))
Submission
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int cnt = 0;
void eliminate(long& n, int nMask)
{
while(n % 10 == 0) {
cnt++;
n /= 10;
}
long mask = floor(pow(10, nMask) + 0.5);
n %= mask;
}
int main() {
int N, K; cin >> N >> K;
long res = 1;
for(int i = 1; i <= N; ++i) {
res *= i;
eliminate(res, K);
}
cout << setw(K) << setfill('0') << res;
cout << " " << cnt;
return 0;
}
7-8 三足鼎立 (25point(s))
Submission
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n; cin >> n;
int P; cin >> P;
vector<int> others(n);
for(int i = 0; i < n;++i) {
cin >> others[i];
}
sort(others.begin(), others.end());
int count = 0;
for(auto iter = others.begin(); iter != others.end(); advance(iter, 1)) {
auto ub = upper_bound(next(iter), others.end(), P + *iter);
auto lb = lower_bound(next(iter), others.end(), abs(P - *iter));
count += (ub - lb);
}
cout << count;
return 0;
}