杭电ACM基础题(1877、1898、1976、1977、1985、1994)

1877、输出A+B的m进制数

输入两个不超过整型定义的非负10进制整数A和B(<=231-1),输出A+B的m (1 < m <10)进制数。
Input
输入格式:测试输入包含若干测试用例。每个测试用例占一行,给出m和A,B的值。
当m为0时输入结束。
Output
输出格式:每个测试用例的输出占一行,输出A+B的m进制数。
Sample Input

8 1300 48
2 1 7
0

Sample Output

2504
1000

Code
输入两个不超过整型定义的非负10进制整数A和B(<=231-1),输出A+B的m(1,10)进制数
除基取余法
*注意考虑a+b=0的情况

//输入两个不超过整型定义的非负10进制整数A和B(<=231-1),输出A+B的m(1,10)进制数。
//除m取余 
#include<iostream>
using namespace std;

//将十进制数n转化为m进制数
int array[1000];
void convert_m(long long c,int m){
    int i=0;
    if(c==0){//考虑a和b都为0的情况 
        cout<<0<<endl;
        return;
    }
    while(c!=0){
        array[i++]=c%m;
        c=c/m;
    }
    for(int k=i-1;k>=0;k--){
        cout<<array[k];
    }
    cout<<endl;
} 

int main(){
    int m;
    int a,b;
    while(cin>>m){
        if(m==0) return 0;
        cin>>a>>b; 
        long long c=a+b;
        //将c转化为m进制的数 
        convert_m(c,m);
    }
    
}

1898 Sempr == The Best Problem Solver?[在T小时的时候,A和B谁提交的问题多]

Now the problem is below: Both of them are perfect problem solvers and they had the same speed, that is to say Sempr can solve the same amount of problems as Xiangsanzi, but Sempr enjoyed submitting all the problems at the end of every A hours but Xiangsanzi enjoyed submitting them at the end of every B hours. In these days, static(Xiaojun Wu) was the assistant coach of hustacm, and he would check the number of problems they solved at time T. Give you three integers A,B,and T, you should tell me who is “The Best New Comers of March”. If they solved the same amount of problems, output “Both!”. If Sempr or Xiangsanzi submitted at time T, static would wait them.
Input
In the first line there is an integer N, which means the number of cases in the data file, followed by N lines.
For each line, there are 3 integers: A, B, T.
Be sure that A,B and N are no more than 10000 and T is no more than 100000000.
Output
For each case of the input, you should output the answer for one line. If Sempr won, output “Sempr!”. If Xiangsanzi won, output “Xiangsanzi!”. And if both of them won, output “Both!”.
Sample Input

3
2 3 4
2 3 6
2 3 9

Sample Output

Sempr!
Both!
Xiangsanzi!

Code:
A同学每a小时提交解决的问题,B同学每b小时提交所有的问题,且A B同学
解决问题的速度相同,问在T小时的时候,A和B谁提交的问题多

/*A同学每a小时提交解决的问题,B同学每b小时提交所有的问题,且A B同学 
解决问题的速度相同,问在T小时的时候,A和B谁提交的问题多 
*/ 
#include<iostream>
using namespace std;
int main(){
    int n;//n个测试用例 
    cin>>n;
    while(n--){
        int a,b,t;
        cin>>a>>b>>t;
        int a1=0,b1=0,t1,t2;
        //A在T内提交的问题数
        for(t1=a;t1<=t;t1=t1+a){
            a1=a1+a;
        }
        //B在T内提交的问题数
        for(t2=b;t2<=t;t2=t2+b){
            b1=b1+b;
        } 
        if(a1>b1){
            cout<<"Sempr!"<<endl;
        }
        else if(a1<b1){
            cout<<"Xiangsanzi!"<<endl;
        }
        else{
            cout<<"Both!"<<endl;
        }
    } 
} 

1976、Software Version[比较软件版本的新旧]

一般来说,软件的版本号由三个部分组成,主版本号(Major Version Number),子版本号(Minor Version Number)和修订号(Revision_Number)。当软件进行了重大的修改时,主版本号加一;当软件在原有基础上增加部分功能时,主版本号不变,子版本号加一;当软件仅仅修正了部分bug时,主版本号和子版本号都不变,修正号加一。
在我们比较软件的两个版本的新旧时,都是先比较主版本号,当主版本号相同时再比较子版本号,前两者都相同的情况下再比较修正号。版本号越大的软件越新。

现在,Lele 在载软件的时候碰到了两个版本,请你告诉他哪个版本更新一些。
Input
输入的第一行有一个整数T,代表有T组测试。接下来有T组测试。
每组测试分两行,第一行有三个整数代表第一个软件版本的主版本号,子版本号和修订号。第二行也有三个整数代表第二个软件版本的主版本号,子版本号和修订号。

数据中出现的整数都在[0,1000]范围之内。
Output
对于每组测试,如果第一个软件的版本新点,请输出"First",如果第二个软件的版本新点,请输出"Second",否则输出"Same"。
Sample Input

3
1 1 0
1 1 1
1 1 1
1 1 0
1 1 1
1 1 1

Sample Output

Second
First
Same

Code
分别给出第一个和第二个软件的主版本号 子版本号 修订号
比较这两个软件哪个比较新
思路:就是比较整数值的大小,可以使用多重if-else 循环

/*分别给出第一个和第二个软件的主版本号 子版本号 修订号
比较这两个软件哪个比较新
思路:就是比较整数值的大小 
*/
#include<iostream>
using namespace std;

struct Version{
    int majver;
    int minver;
    int rever;
} soft[2];

int main(){
    int t;//t组测试用例
    cin>>t;
    while(t--){
        cin>>soft[0].majver>>soft[0].minver>>soft[0].rever;
        cin>>soft[1].majver>>soft[1].minver>>soft[1].rever;
        if(soft[0].majver>soft[1].majver){
            cout<<"First"<<endl;
        }
        else if(soft[0].majver<soft[1].majver){
            cout<<"Second"<<endl;
        }
        else{
            if(soft[0].minver>soft[1].minver){
                cout<<"First"<<endl;
            }
            else if(soft[0].minver<soft[1].minver){
                cout<<"Second"<<endl;
            }
            else{
                if(soft[0].rever>soft[1].rever){
                    cout<<"First"<<endl;
                }
                else if(soft[0].rever<soft[1].rever){
                    cout<<"Second"<<endl;
                }
                else{
                    cout<<"Same"<<endl;
                }
            }
        }
    } 
} 

1977、Consecutive sum II[找规律]

Consecutive sum come again. Are you ready? Go ~~
1 = 0 + 1
2+3+4 = 1 + 8
5+6+7+8+9 = 8 + 27

You can see the consecutive sum can be representing like that. The nth line will have 2*n+1 consecutive numbers on the left, the first number on the right equal with the second number in last line, and the sum of left numbers equal with two number’s sum on the right.
Your task is that tell me the right numbers in the nth line.
Input
The first integer is T, and T lines will follow.
Each line will contain an integer N (0 <= N <= 2100000).
Output
For each case, output the right numbers in the Nth line.
All answer in the range of signed 64-bits integer.
Sample Input

3
0
1
2

Sample Output

0 1
1 8
8 27

Code

/*
第0行:1=0+1;
第1行:2+3+4=1+8;
第2行:5+6+7+8+9=8+27;
.....
第n行:左边共有2*n+1个数,右边由两个数组成,且右边第一个数等于第n-1行右边第二个数
求:第i行右边的数为什么 
*/
#include<iostream>
using namespace std;
int main(){
    int t;//t组测试用例
    cin>>t;
    while(t--){
        __int64 n;
        cin>>n;
        //第n行,左边第一个数n*n+1,左边共2*n+1个数 
        //第n行,右边第一个数为n*n*n;
        __int64 b=n*n*n;
        __int64 c=(n+1)*(n+1)*(n+1);
        cout<<b<<" "<<c<<endl; 
    } 
} 

1985、Conversions[单位转换]

Conversion between the metric and English measurement systems is relatively simple. Often, it involves either multiplying or dividing by a constant. You must write a program that converts between the following units:
在这里插入图片描述
Input
The first line of input contains a single integer N, (1 ≤ N ≤ 1000) which is the number of datasets that follow.
Each dataset consists of a single line of input containing a floating point (double precision) number, a space and the unit specification for the measurement to be converted. The unit specification is one of kg, lb, l, or g referring to kilograms, pounds, liters and gallons respectively.
Output
For each dataset, you should generate one line of output with the following values: The dataset number as a decimal integer (start counting at one), a space, and the appropriately converted value rounded to 4 decimal places, a space and the unit specification for the converted value.
Sample Input

5
1 kg
2 l
7 lb
3.5 g
0 l

Sample Output

1 2.2046 lb
2 0.5284 g
3 3.1752 kg
4 13.2489 l
5 0.0000 g

Code

/*单位之间进行转化  kg和1b之间  g和l之间转换 
1kg=2.2046 1b; 1 1b=0.4536kg;
1l=0.2642g; 1g=3.7854l; 
*/
#include<iostream>
#include<iomanip>
#include<cstring>
using namespace std;
int main(){
    int n,i=0;
    cin>>n;
    float a;
    char c[3];
    while(n--){
        i++;
        cin>>a>>c;
        cout<<setiosflags(ios::fixed);
        if(strcmp(c,"kg")==0){//将a kg转化为1b 
            cout<<i<<" "<<setprecision(4)<<a*2.2046<<" "<<"lb"<<endl;
        }
        else if(strcmp(c,"lb")==0){//将a 1b转化为kg 
            cout<<i<<" "<<setprecision(4)<<a*0.4536<<" "<<"kg"<<endl;
        }
        else if(strcmp(c,"g")==0){//将a g转化为l 
            cout<<i<<" "<<setprecision(4)<<a*3.7854<<" "<<"l"<<endl;
        }
        else{
            cout<<i<<" "<<setprecision(4)<<a*0.2642<<" "<<"g"<<endl;
        }
    }
    return 0;
} 

1994、利息计算

为自行解决学费,chx勤工俭学收入10000元以1年定期存入银行,年利率为3.7% 。利率
按年计算,表示100元存1年的利息为3.7元.实际上有时提前有时推迟取,因此实际利息按天
计算,1年按365天计算,因此Q天的利息是
本金3.7/100 Q/365
存了100天后1年定期年利息提高到3.9%。如将存款提前全取出,再存1年定期。那么前面的
100天只能按活期利息1.7%计算。
100天的利息和本金:10000(1+1.7/100
100/365)=10046.6
再存1年定期 :10046.6(1+3.9/100)=10438.4
得到的利息加本金为10438.4
如果无视利息的提高,再存1年。得到的利息加本金为(定期推迟取,利率不变)
10000(1+3.7/100
(100+365)/365)=10471.4
Input
输入数据有多组,第1行为整数T,是数据的组数.每组占一行5个数,Y-存入的本金<=100000,
Q-已存天数<=365,e-活期利率,f-定期利率,g-提高后的定期利率.
Output
每组数据输出2行.
第1行,提前支取后再存1年所得本金和利息.
第2行,继续存1年,Q+365天后所得本金和利息.
Sample Input

4 
10000 100 2.3 3.7 3.9
10000 100 1.7 3.7 3.9 
10000 200 1.7 3.7 3.9 
10000 300 1.7 3.7 3.9 

Sample Output

10455.5
10471.4
10438.4
10471.4
10486.8
10572.7
10535.2
10674.1

Code:
利息的计算,简单

/*简单的数学问题——存入银行的本金利息计算 
*/
#include<iostream>
using namespace std;
int main(){
    int t;//t组数据
    double a,b,c;
    cin>>t;
    while(t--){
        double money,e,f,g;//本金、活期利率、定期利率、提高后的利率 
        int days;//已存入的天数
        cin>>money>>days>>e>>f>>g;
        //提前支取后再存1年所得本金和利息
        a=money*(1+e/100*days/365);//提前支取后的本金+利息
        b=a*(1+g/100);//再将其存入银行一年后的本金+利息 
        cout<<b<<endl;
        //继续存1年,Q+365天后所得本金+利息 
        c=money*(1+f/100*(days+365)/365);
        cout<<c<<endl;
    } 
    return 0;
} 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值