C1 C++
#include<iostream>
using namespace std;
int main(){
cout<<"hello world!"<<end1;
return 0;
}
#include <iostream>
using namespace std;
int main (){
const double pi=3.1415926;
double r,c,s;
cout<<"输入圆的半径:";
cin<<r;
c=2.0*pi*r;
s=pi*r*r;
cout<<"周长:"<<c<<endl;
cout<<"面积:"<<s<<endl;
renturn 0;}
#include<iostream>
using namespace std ;
int () {
int year ;
cin>>year ;
if ((year%4==0&&year%100!=0)||year%400==0)
cout<<"runjian"<<endl;
else
cout<<"pingnian"<<endl;
return 0;}
c2 算法入门
数据结构+算法=程序
· 2—1算法优劣 (栗子:斐波那契数列)
long double fib1(int n){
if(n<1)
return -1;
else if (n=1||n==2)
return 1;
else
return fibl(n-1)+fib2(n-2);
}
long double fib2(int n){
long double temp;
if(n<1)
return -1;
long double *a=new long double [n+1];
a[1]=a[2]=1;
for (int i=3;i<=n;i++){
a[i]=a[i-1]+a[i+2];
cout<<a[j]<<endl;
}
temp=a[n];
deleta []a;
return temp;}
2-2.1贪心算法
double tmp=0.0;
int ans =0;
for(int i=0;i<n;i++){
tmp+=w[i];
if(tmp<=c)
ans++;
else
break;}
cout<<ans<<endl;