#include
using namespace std;
int n, k, cnt = 0;
void dep(int x) {
int a;
while(x > 1) {
a = x % 10;
if (a == k) cnt++;
x = x / 10;
}
}
int main() {
cin >> n >> k;
dep(n);
cout << cnt << endl;
return 0;
}
#include
using namespace std;
char st[100];
int cnt[100];
int len, sum = 0;
int main() {
scanf("%s", st);
len = strlen(st);
for(int i = 0; i < len; i++) {
if (st[i] >= 'a' && st[i] <= 'z') st[i] = st[i] - 'a' + 'A';
}
for(int i = 0; i < len; i++) {
if (st[i] >= 'A' && st[i] <= 'Z') {
cnt[st[i]-'A']++;
}
}
for(int i = 0; i < 26; i++) {
printf("%d ", cnt[i]);
sum = sum + cnt[i];
}
printf("\n");
printf("%d\n", sum);
return 0;
}
#include
using namespace std;
int n, sum = 0, js = 0;
int a[1005], b[1005], maxn = 0;
int main() {
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> a[i];
b[a[i]]++;
if (a[i] > maxn) maxn = a[i];
}
for(int i = maxn; i >= 1; i--) {
if (b[i] > 0) {
js = js + 1;
if (js % 2 == 0) sum += b[i];
}
}
cout << sum << endl;
return 0;
}
#include
using namespace std;
int n, k, live[100];
int main() {
cin >> n >> k;
for(int i = 1; i <= n; i++) live[i] = 1;
int ind=0;
for(int i = 1; i < n; i++) {
int bs = 0;
while(bs != k) {
ind++;
if (ind > n) ind = 1;
if (live[ind]==1) bs++;
}
live[ind] = 0;
}
for(int i = 1; i <= n; i++)
if (live[i] == 1) cout << i << ' ';
return 0;
}
#include
using namespace std;
int n, w1 = 0, w2 = 0;
int a[100], b[100];
int main() {
int x, y;
cin >> n;
for(int i = 1; i <= n; i++) {
a[i] = 0;
b[i] = 0;
}
for(int i = 1; i <= n; i++) {
cin >> x >> y;
if (a[x] != 0) b[a[x]] = 0;
else w1++;
a[x] = y;
b[y] = x;
}
for(int i = 1; i <= n; i++) {
if (a[i] > 0) w2++;
if (b[i] > 0) w2++;
}
cout << w1*2-w2 << endl;
return 0;
}
#include
using namespace std;
int n, a[1000], b[1000];
int ff(int l, int r) {
if (l == r) return 1;
int mid = (l+r) / 2, Lv = 0, Rv = 0;
for(int i = l; i <= mid; i++)
if (a[i] > b[i]) {
Lv++;
int tmp = a[i];
a[i] = b[i];
b[i] = tmp;
}
for(int i = mid+1; i <= r; i++)
if (b[i] > a[i]) {
Rv++;
int tmp = a[i];
a[i] = b[i];
b[i] = tmp;
}
int lf = ff(l, mid);
int rf = ff(mid+1, r);
return lf * Lv + rf * Rv;
}
int main() {
cin >> n;
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < n; i++) cin >> b[i];
cout << ff(0, n-1) << endl;
42题 | 被引用0次