A. Digits Sum
找规律题,没想到看样例直接蒙对……
#include <iostream>
using namespace std;
int main() {
int t, n;
cin >> t;
while (t--) {
cin >> n;
cout << (n + 1) / 10 << endl;
}
return 0;
}
B. Reverse String
感觉是前四题中最难的。
Pretest AC,System Test WA。
#include <iostream>
#include <string>
using namespace std;
int main() {
int q, ok, ps, pt, n;
string s, t;
cin >> q;
while (q--) {
cin >> s >> t;
for (int i = 0; i < s.length(); i++) {
for (ps = i, pt = 0, ok = 1; ps < s.length() && pt < t.length() && s[ps] == t[pt]; ps++, pt++);
for (ps -= 2; pt < t.length(); ps--, pt++)
if (s[ps] != t[pt] || ps < 0) {ok = 0; break;}
if (ok) { cout << "YES" << endl; break;}
}
if (!ok) cout << "NO" << endl;
}
return 0;
}
C. Penalty
忘记初始化变量,卡了半天……
#include <iostream>
using namespace std;
int main() {
int t, aw, al, at, bw, bl, bt, ok;
char a[12];
cin >> t;
while (t--) {
aw = al = bw = bl = 0;
at = bt = 5;
ok = 0;
cin >> a + 1;
for (int i = 1; i <= 10; i++) {
if (i % 2) {
at--;
switch (a[i]) {
case '1': al++;
case '?': aw++;
}
} else {
bt--;
switch (a[i]) {
case '1': bl++;
case '?': bw++;
}
}
if (al + at < bw || bl + bt < aw) {
ok = 1;
cout << i << endl;
break;
}
}
if (!ok) cout << 10 << endl;
}
return 0;
}
D. Backspace
像极了B……
#include <iostream>
#include <string>
using namespace std;
int main() {
int q, ps, pt, ok;
string s, t;
cin >> q;
while (q--) {
cin >> s >> t;
for (ps = pt = 0, ok = 1; pt < t.length() && ok; ps++, pt++)
while (s[ps] != t[pt]) {
ps += 2;
if (ps >= s.length()) {ok = 0; break;}
}
if (!ok || (s.length() - ps) % 2)
for (ps = 1, pt = 0, ok = 1; pt < t.length() && ok; ps++, pt++)
while (s[ps] != t[pt]) {
ps += 2;
if (ps >= s.length()) {ok = 0; break;}
}
if (!ok || (s.length() - ps) % 2) cout << "NO" << endl;
else cout << "YES" << endl;
}
return 0;
}
后面的来不及做不会了……