// w.cpp : Defines the entry point for the console application.
//
//①//100高落地 反弹原来高度一半 求第10次落地,共经?米和 第10次返回的高度
#include "stdafx.h"
#include<iostream>
using namespace std;
int main(int argc, char* argv[])
{
float sum=100.0,h=sum/2;
for(int i=2;i<=10;i++)
{
sum+=h*2; //10次落地sum
h=h/2; // 第10次反弹高度
}
cout<<sum<<" "<<h;
return 0;
}
//② 猴子偷桃 第十天只有一个了。每次吃上一天的一般多一个
#include "stdafx.h"
#include<iostream>
using namespace std;
int main(int argc, char* argv[])
{
int num1,num2=1;
int day=9;
while(day>0)
{
num1=(num2+1)*2;
num2=num1;
day--;
}
cout<<num1;
return 0;
}
//③ 甲a b c乙 x y z 两队比赛 a说不和x比 b说不和 y z比
#include "stdafx.h"
#include<iostream>
using namespace std;
int main(int argc, char* argv[])
{
char i,j,k;// 分别为a b c 对手
for(i='x';i<='z';i++)
for(j='x';j<='z';j++)
if(i!=j)
for(k='x';k<'z';k++)
{
if(i!=k &&j!=k)
{
if(i!='x'&&k!='x'&&k!='z')
cout<<i<<" "<<j<<" "<<k<<endl;
}
}
return 0;
}
//④ 求 2/1 3/2 5/3.......求出这个数列的前20项
#include<iostream>
using namespace std;
int main(int argc, char* argv[])
{
float sum=0;
int i;
int fz=2,fm=1;
for(i=1;i<=20;i++)
{
sum+= fz/fm;
fz=fz+fm;
fm=fz;
}
cout<<sum;
return 0;
}
//⑤输入5字符 逆序输出 递归 //相当于栈
#include<iostream>
using namespace std;
void palin(int n)
{
char next;
if(n<=1)
{
next=getchar();
putchar(next);
}
else
{
next=getchar();
palin(n-1);
putchar(next);
}
}
int main(int argc, char* argv[])
{
int i=5;
palin(5);
return 0;
}
//⑥ 给出一个5位数 判断回文数问题 12321是回文数
#include<iostream>
using namespace std;
int main(int argc, char* argv[])
{
int n;
int w,q,b,s,g;
cin>>n ;
w=n/10000;
q=n%10000/1000;
b=n%10000%1000/100;
s=n%10000%1000%100/10;
g=n%10000%1000%100%10;
if(w==g &&q==s)
{
cout<<"yes";
}
else
cout<<"no";
return 0;
}
//⑦ 输入一个字母 判断星期几 如果重复 输入第二个字母
#include<iostream>
using namespace std;
#include<conio.h> //key code
int main(int argc, char* argv[])
{
char letter;
cin>>letter;
switch(letter)
{
case 'M':cout<<"一";break;
case 'T':cout<<"input second character";
if(letter=getch()=='u')
cout<<"二";
else if(letter=getch()=='h')
cout<<"四";
else return 0;
break;
case 'W':cout<<"三";break;
case 'F':cout<<"五";break;
case 'S':cout<<"input second character";
if(letter=getch()=='a')
cout<<"六";
else if(letter=getch()=='u')
cout<<"日";
else return 0;
break;
}
return 0;
}