CF328解题报告

A题:IQ Test

很水的题,就是给出数列的前四项,判断出是等比还是等差。求下一项。

code:

#include <iostream>

using namespace std;

int main()
{
    int a,b,c,d;
    cin >> a  >> b >> c >> d ;
    if(a + c == 2 * b && b + d == 2 * c)
    cout << 2 * d - c << endl ;
    else if(a * c == b * b && b * d == c * c)
    {
        if(d * d % c == 0)
        cout << d * d / c << endl ;
        else
        cout << 42 << endl ;
    }
    else
    cout << 42 << endl ;

    return 0;
}


B题:Sheldon and Ice Pieces

题意:有一排卡片,每张卡片上都有一个数字,下面给出一个序列,想要组成一个数,其中2和5可以互用,6和9可以互用,问在这个序列中能组成多少个这个数?

思路:求出给出序列的每个数出现的次数,在计算想要组成的数每个数出现的次数,当然 2和5、6和9的和算在一起。然后用给出序列的每个数字的和除以想要组成的数字的和,再取最小值即可。

code:

#include <iostream>
#include <stdio.h>
#include <string>
#include <cmath>
#include <cstring>
using namespace std;
const int N=1000;
int sum[9] , sum1[9] ;
int minn = N ;
int min(int a[],int n)
{
    int i ;
    for(i = 1 ; i < n ; i ++)
    {
        if(a[0] > a[i])
            a[0] = a[i] ;
    }
    return a[0] ;
}
int main()
{
    memset(sum,0,sizeof(sum)) ;
    string s , t ;
    int i , count = 0 ;
    cin >> s ;
    cin >> t ;
    int l1 = s.length() ;
    int l2 = t.length() ;
    for(i = 0 ; i < l2 ; i ++)
    {
        if(t[i] == '5' || t[i] == '9')
            t[i] = t[i] - 3 ;
        sum[t[i] - '0'] ++ ;
    }
    for(i = 0 ; i < l1 ; i ++)
    {
        if(s[i] == '5' || s[i] == '9')
            s[i] = s[i] - 3 ;
        sum1[s[i] - '0'] ++ ;
    }
    for(i = 0 ; i < l1 ; i ++)
    {
        if(sum1[s[i] - '0'] != 0)
        {
            int a = sum[s[i] - '0'] / sum1[s[i] - '0'] ;
            if(minn > a)
                minn = a;
        }
    }
    cout << minn << endl ;
    return 0;
}


 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值