ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

eighth

2021-03-05 16:04:30  阅读:214  来源: 互联网

标签:首字母 int ++ include class2 eighth class1


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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有