A 从左往右扫一遍统计答案,如果等于n就输出n,否则再从右往左扫一遍,再原来的答案上累加答案 #include iostream#include cstdiousing namespace std;int a[105], n, k;int main() { cin n k; for (int i = 1; i
A
从左往右扫一遍统计答案,如果等于n就输出n,否则再从右往左扫一遍,再原来的答案上累加答案
#include <iostream> #include <cstdio> using namespace std; int a[105], n, k; int main() { cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> a[i]; int ans = 0; for (int i = 1; i <= n; ++i) { if (a[i] <= k) ++ans; else break; } if (ans == n) { cout << n << endl; return 0; } for (int i = n; i >= 1; --i) { if (a[i] <= k) ++ans; else break; } cout << ans << endl; return 0; }
B
扫一遍,如果能被n整除,那就翻转从1到这里的整个区间
#include <iostream> using namespace std; int main(){ int n; string s; cin>>n>>s; for(int i=1;i<=n;i++) if(n%i==0) for(register int j=0;j<i/2;j++) { char temp=s[j]; s[j]=s[i-j-1]; s[i-j-1]=temp; } cout<<s<<endl; return 0; }