目录
A:Random Number Checker
题面:
题意:给定一个序列,如果序列中奇数的数量和偶数的数量差值不超过1就输出Good,否则就输出Not Good
思路:签到题
这题题目意思很简单,但是由于翻译对于那句 If the difference between the number of occurrences of odd and even numbers is at most one, she thinks the generator is good.的理解不是很到位,导致wa2,以及20min后出题
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
while(cin >> n){
int a;
int x = 0, y = 0;
for(int i = 0; i < n; i++){
cin >> a;
if(a & 1){
x++;
}else{
y++;
}
}
if(abs(x - y) > 1){
cout << "Not Good" << endl;
}else{
cout << "Good" << endl;
}
}
return 0;
}
B:Arithmetic Exercise
题目描述:
输入描述: 输出描述:
样例:
题意:a / b保留k位小数(4舍5入)
思路:简单除法模拟题(数据有点水)
这个就是很水的除法模拟,然后我和另一个队友不确定k的作用就在等A出了后才过
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
int main(){
ll a, b, k;
while(cin >> a >> b >> k){
string s = "";
int ans = a / b;
string ss = "";
if(ans == 0){
s += '0';
}
while(ans){
ss += (ans % 10 + '0');
ans /= 10;
}
reverse(ss.begin(), ss.end());
s += ss;
s += '.';
int cnt = a % b;
for(int i = 0; i < k; i++){
cnt *= 10;
ans = cnt / b;
s += ans + '0';
cnt = cnt % b;
if(i == k - 1){
if(cnt * 10 / b >= 5){
bool f = 1;
for(int i = s.length() - 1; i >= 0; i--){
if(s[i] == '.'){
continue;
}
if(f){
s[i] ++;
f = 0;
if(s[i] > '9'){
f = 1;
s[i] = '0';
}
}
}
}
}
}
cout << s << endl;
// cout << endl;
}
return 0;
}