A. Detective Book
代码:
#include <bits/stdc++.h> using namespace std; const int maxn = 1e4 + 10; int N; int a[maxn]; int maxx = 0; int main() { scanf("%d", &N); for(int i = 0; i < N; i ++) scanf("%d", &a[i]); int ans = 0; for(int i = 0; i < N; i ++) { maxx = max(a[i], maxx); if(maxx == i + 1) ans ++; } printf("%d\n", ans); return 0; }
B. Good String
代码:
#include <bits/stdc++.h> using namespace std; int T, N; string s; int main() { scanf("%d", &T); while(T --) { scanf("%d", &N); cin >> s; int st, en; if(s[0] == ‘>‘) printf("0\n"); else if(s[N - 1] == ‘<‘) printf("0\n"); else { for(int i = 0; i < N; i ++) { if(s[i] == ‘>‘) { st = i; break; } } for(int i = N - 1; i >= 0; i --) { if(s[i] == ‘<‘) { en = i; break; } } printf("%d\n", min(st, N - 1 - en)); } } return 0; }
原文地址:https://www.cnblogs.com/zlrrrr/p/10713874.html
时间: 2024-10-12 15:55:56