【SUSTOJ】愚人節場(做做看7)題解
2020年東京奧運會
輸出 “2021” 即可,不知道原因請百度。
自然語言處理
只有中文,日語和英語。這三種語言有着明顯的特徵。
黃色字體只不過是個煙霧彈,其實並沒有很難。
中文:由聲母和韻母組成。
日語:由五十音組成(樣例中已經包含了大部分)。
英語:有明顯的單詞特徵。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
using namespace std;
string shengmu[23] = {"b", "p", "m", "f", "d", "t", "n", "l", "g", "k", "h", "j", "q", "x",
"zh", "ch", "sh", "r", "z", "c", "s", "y", "w"};
string yunmu[23] = {"a", "o", "e", "i", "u", "v", "ai", "ei", "ui", "ao", "ou", "iu", "ie", "er", "an", "en", "in", "un", "ang", "eng", "ing", "ong"};
vector<string> zhongwen;
char riyu[20][10] = {"ts", "ki", "ma", "ha", "ni", "ta", "ka", "ra", "ku", "mo", "no", "su", "tsu", "wa", "ko", "ji", "aru", "shi", "te", "au"};
string yingyu[20] = {"the", "was", "is", "are", "am", "were", "they", "that", "for", "to", "and", "or", "than", "a", "of", "those", "these", "this", "from", "time"};
int main() {
for (int i = 0; i < 20; i++) {
for (int j = 0; j < 20; j++) {
zhongwen.push_back(shengmu[i] + yunmu[j]);
}
}
int cnt = 0, English = 0, Chinese = 0, Japanese = 0;
string str;
while (cin >> str) {
int len = str.length();
for (int i = 0; i < len; i++) {
if (str[i] >= 'A' && str[i] <= 'Z') {
str[i] = str[i] - 'A' + 'a';
}
}
for (int i = 0; i < 20; i++) {
if (yingyu[i] == str) {
English++;
break;
}
}
int len_c = zhongwen.size();
for(int i = 0; i < len_c; i++) {
if (str == zhongwen[i]) {
Chinese++;
break;
}
}
for(int i = 0; i < 20; i++) {
if (strstr(str.c_str(), riyu[i]) != NULL) {
Japanese++;
break;
}
}
}
if (English > 10) {
cout << "English" << endl;
} else if (Chinese >= Japanese && Chinese >= English) {
cout << "Mandarin" << endl;
} else {
cout << "Japanese" << endl;
}
return 0;
}
幸運數字
已知 可以唯一的表示爲 。(, 均爲素數)
結論:若存在 使得 ,當且僅當 或
證明:若存在 使得 , 且
則必有 或 ,則 , 不爲素數,與題述矛盾。
#include <iostream>
using namespace std;
int main() {
long long n, a;
while(~scanf("%lld", &n)) {
for(int i = 2; i * i <= n; i++)
if(n % i == 0) {
printf("%lld\n", n/i);
break;
}
}
return 0;
}
三角形的面積
重點在於理解 “相鄰兩組測試數據輸出之間有一個空行” 中的 “相鄰” 和 “之間” 的關係。(不過可能評測姬沒有檢測到)
並且注意要使用 double 而非 float。
題目沒有說明 T 的大小,請不要使用數組來存放輸入的數據用於離線處理。
(後臺有10萬組測試樣例)
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int t, x, y, z;
scanf("%d", &t);
while(t--) {
scanf("%d %d %d", &x, &y, &z);
if(x + y > z && x + z > y && y + z > x) {
double p = (x + y + z) / 2.0;
double area = sqrt(p * (p - x) * (p - y) * (p - z));
printf("%.3f\n", area);
}
else {
printf("-1\n");
}
if (t != 0) printf("\n");
}
return 0;
}