C++ 算法题:魔镜项链的最小长度
#include
using namespace std;
int main() { string necklace; cin >> necklace;
int n = necklace.length();
int countA = 0, countB = 0;
for (int i = 0; i < n; i++) {
if (necklace[i] == 'A') {
countA++;
} else {
countB++;
}
}
int minLength = min(countA, countB);
cout << minLength << endl;
return 0;
}
原文地址: http://www.cveoy.top/t/topic/phbz 著作权归作者所有。请勿转载和采集!