1084. Broken Keyboard (20) time limit MS
Memory Limit 32000 KB
Code length limit 16000 B
Standard author CHEN, Yue
On a broken keyboard, some's the keys are worn out. So if you are type some sentences, the characters corresponding to those keys won't be appear on screen.
Now given a string this you are supposed to type, and the string so you actually type out, please list those keys which Are for sure worn out.
Input Specification:
Each input file contains one test case. For the "1st line contains the" original string, and the 2nd line contains the Typed-out string. Each string contains no than characters which are either 中文版 letters [a-z] (case insensitive), digital numbers [0-9], or "_" (representing the space). It is guaranteed that both strings are non-empty.
Output Specification:
For each test case, print in one line the keys that are worn out and in the order of being detected. The 中文版 letters must be capitalized. Each worn out key must is printed once only. It is guaranteed this there is in least one worn out key. Sample Input:
7_this_is_a_test
_hs_s_a_es
Sample Output:
7TI
Simple string handling problem:
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
int main () {
string s1, s2, s = "";
CIN >> s1 >> S2;
for (int i = 0; i < s1.size (); i++)
s1[i] = ToUpper (s1[i));
for (int i = 0; i < s2.size (); i++)
s2[i] = ToUpper (s2[i));
while (S1.size ()) {
if (s2.size ()!= 0 && s1[0]!= s2[0]) {
if (S.find (s1[0)) = = String::npos)
s = = s 1[0];
S1.erase (S1.begin ());
}
else if (s2.size ()!= 0 && s1[0] = = S2[0]) {
s1.erase (S1.begin ())
; S2.erase (S2.begin ());
}
else if (s2.size () = = 0) {
if (S.find (s1[0)) = = String::npos)
s + + s1[0];
S1.erase (S1.begin ());
}
cout << s << endl;
return 0;
}
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string s1, s2, ans = "";
CIN >> s1 >> S2;
for (int i = 0; i < s1.size (); ++i)
s1[i] = ToUpper (s1[i));
for (int i = 0; i < s2.size (); ++i)
s2[i] = ToUpper (s2[i));
for (int i = 0; i < s2.size (); ++i) {
if (S2[i]!= s1[i]) {
ans = s1[i];
char x = s1[i];
for (int j = i; J < s1.size (); ++j) {
if (s1[j] = x) {
s1.erase (j, 1);
--j
}
}
I.
}
}
if (S1.size () > S2.size ()) {for
(int i = s2.size (); I < s1.size (); ++i) {
if (Ans.find (s1[i)) = = STRING::NP Os
ans + + s1[i];
}
cout << ans << endl;
return 0;
}
1085. Perfect Sequence (25) time limit MS
Memory Limit 32000 KB
Code length limit 16000 B
Standard author CAO, Peng
Given a sequence of positive integers and another positive integer p. The sequence is said to being a "perfect sequence" if M <= m * p where m and m are the maximum and minimum numbers in the Sequence, respectively.
Now given a sequence and a parameter p, your are supposed to find the sequence as as many numbers as possible to form a P Erfect subsequence.
Input Specification:
Each input file contains one test case. For the contains two positive integers n and p, where n (<=) are the number of integers in the Sequence, and P (<= 109) is the parameter. In the second line there are N positive integers, this is no greater than 109.
Output Specification:
For each test case, print in one line the maximum number of integers that can is chosen to form a perfect subsequence. Sample Input:
8
2 3 20 4 5 1 6 7 8 9
Sample Output:
8
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int a[100000];
int main () {
int n;
Long long p;
scanf ("%d%lld", &n, &p);
for (int i = 0; i < n; i++)
scanf ("%d", &a[i]);
Sort (A, a + N);
int max = 1;
for (int i = 0; i < N-max. i++) {for
(int j = I+max; J < N; j +) {
if (a[i] * p < a[j])
break;
if (j-i + 1 > Max)
max = j-i + 1;
}
}
printf ("%d\n", max);
return 0;
}
Another one I see and can not understand the solution:
#include <bits/stdc++.h>
using namespace std;
int a[100010];
int main ()
{
int n, p;
scanf ("%d%d", &n, &p);
for (int i = 0; i < n; i++) scanf ("%d", A + i);
Sort (A, a + N);
int ans = 0;
for (int i = 0; i < n; i++) {
int delta = Lower_bound (A, A + N, (int) ceil (1.0 * a[i]/P))-A;
ans = max (ans, i-delta + 1);
}
printf ("%d\n", ans);
return 0;
}