eighth
作者:互联网
CodeForces - 1166A
题意:一个人数n,有n个人名,要把他们分到两个教室里,名字首字母的尽量不要放一起,如果有名字首字母一样的放一起,就要加一张凳子。
思路:开两个数组,只要每次读入把名字放到相同首字母比较少的那个数组里就好了。
#include <iostream> #include <cstring> #include <algorithm> #include <cmath> using namespace std; int main() { int n; cin >> n; int class1[110], class2[110]; memset(class1, 0, sizeof(class1)); memset(class2, 0, sizeof(class2)); string s; for (int i = 0; i < n; i++) { cin >> s; if (class1[s[0] - 'a'] < class2[s[0] - 'a']) class1[s[0] - 'a'] ++; else class2[s[0] - 'a'] ++; } int res = 0; for (int i = 0; i < 26; i++) { res += class1[i] * (class1[i] - 1) / 2; res += class2[i] * (class2[i] - 1) / 2; } cout << res << endl; return 0; }
CodeForces - 1166B
思路:
k必然要大于等于25
第一行:aeiou循环
第二行:eioua循环
第三行:iouae循环
第四行:ouaei循环
第五行:uaeio循环
#include <iostream> #include <cstring> #include <algorithm> #include <cmath> using namespace std; int n , k , m; bool isprime(int x) { for(int i = 2 ; i <= sqrt(x) ; i ++ ) if(x % i == 0) { if(i < 5 || (x / i) < 5) continue; else { n = i; m = x / i; return false; } } return true; } int main() { string s1 = "aeiou"; string s2 = "eioua"; string s3 = "iouae"; string s4 = "ouaei"; string s5 = "uaeio"; cin >> k; if(k < 25 || isprime(k)) cout << "-1" << endl; else { for(int i = 0 ; i < n ; i ++ ) { int l = i % 5; if(l == 0) for(int j = 0 ; j < m ; j ++ ) cout << s1[j % 5]; if(l == 1) for(int j = 0 ; j < m ; j ++ ) cout << s2[j % 5]; if(l == 2) for(int j = 0 ; j < m ; j ++ ) cout << s3[j % 5]; if(l == 3) for(int j = 0 ; j < m ; j ++ ) cout << s4[j % 5]; if(l == 4) for(int j = 0 ; j < m ; j ++ ) cout << s5[j % 5]; } cout << endl; } return 0; }
标签:首字母,int,++,include,class2,eighth,class1 来源: https://www.cnblogs.com/yctql/p/14486705.html