2014真题

第一题:
n的阶乘
代码
#include <bits/stdc++.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system(“pause”) or input loop /
string f(int n){
int temp=0;
if(n1) return “1”;
else {
string a=f(n-1);
int len=a.length(),i=len-1;
while(i>=0){
temp+=(a[i]-‘0’)*n;
a[i]=temp%10+‘0’;
temp/=10;
i–;
}
if(temp!=0) a=to_string(temp)+a;
i=0;
while(a[i]
‘0’&&i<a.length()-1) i++;
return a.substr(i);
}
}
int main(int argc, char
* argv) {
int n;
cin>>n;
cout<<f(n);
return 0;
}
第二题
已知年,和n,求是几月几日
#include <bits/stdc++.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system(“pause”) or input loop /
int isleapyear(int year){
if(year%40||(year%100!=0&&year%4000))
return 1;
else
return 0;
}
int month[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},
{0,31,29,31,30,31,30,31,31,30,31,30,31}};
int main(int argc, char
* argv) {
int year,n,j=1;
cin>>year>>n;
int k=isleapyear(year);
while(n>month[k][j]){
n-=month[k][j];
j++;
}
cout<<j<<" "<<n;
return 0;
}
第三题
去重复,排序
#include <bits/stdc++.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system(“pause”) or input loop /
int main(int argc, char
* argv) {
int n,temp;
cin>>n;
setres;
for(int i=0;i<n;i++){
cin>>temp;
res.insert(temp);
}
for(auto it=res.begin();it!=res.end();it++)
cout<<it;
}
第四题
#include <bits/stdc++.h>
using namespace std;
/
run this program using the console pauser or add your own getch, system(“pause”) or input loop /
const int MAX=100;
int dp[MAX][MAX],a[MAX][MAX];
int main(int argc, char
* argv) {
int n;
cin>>n;
for(int i=0;i<n;i++){
for(int j=0;j<=i;j++){
cin>>a[i][j];
dp[i][j]=a[i][j];
}
}
for(int i=n-1;i>=0;i–){
for(int j=0;j<=i;j++){
dp[i][j]+=max(dp[i+1][j],dp[i+1][j+1]);
}
}
cout<<dp[0][0]<<endl;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值