A. XXXXX
题目大意:(文末原题)
给出一个字符串,判断能否从 开头或末尾 删去部分元素,使这个子串的元素和不被x整除,输出最长字串长度;
思路:
双指针,一个循环删除开头的元素,另一个循环删除末尾的元素,每次判断能否整除;
代码:
#include <iostream> using namespace std; const int maxn = 1e5 + 10; int main() { int t; cin >> t; while(t--) { int a[maxn]; int n, x, d = 0; cin >> n >> x; long long s = 0, m; for(int i = 0; i < n; i++) { cin >> a[i]; s += a[i]; } m = s; if(s % x) { cout << n << endl; continue; } fo