将之前的文章做了一个总结
文章目录
7-1:厘米换算英尺英寸
1.题目:
2.源码:
#include<iostream>
using namespace std;
int main()
{
int m;
cin >> m;
int inch, foot;
foot = (int)(m / 30.48)/1;
inch = ((m / 30.48) - foot)*12;
printf("%d %d", foot, inch);
return 0;
}
7-2:然后是几点
1.题目:
2.源码:
#include<stdio.h>
int main()
{
int t1,t2,h1,h2,m1,m2;
scanf("%d %d",&t1,&t2);
h1=t1/100;//起始的小时
m1=t1%100;//起始的分钟
if(t2>=0)
{
h1=h1+(m1+t2)/60;
m1=(m1+t2)%60;
}
else
{
int ret=h1*60+m1+t2;//ret表示总分钟
h1=ret/60;
m1=ret%60;
}
printf("%d%02d",h1,m1);//%02d是将数字按宽度为2,采用右对齐方式输出,若数据位数不到2位,左边补0
return 0;
}
7-3:逆序的三位数
1.题目:
2.源码:
#include<iostream>
using namespace std;
int main ()
{
int n,a,b,c;
cin>>n;
a=n/100;
b=(n%100)/10;
c=n%10;
cout<<c*100+b*10+a<<endl;
return 0;
}
7-4:BCD解密
1.题目:
2.源码:
#include<iostream>
using namespace std;
int main ()
{
int n;
cin>>n;
int i=n/16;
int j=n%16;
if(n==0)
printf("0");
else
printf("%d%d",i,j);
return 0;
}
7-5:表格输出
1.题目:
2.源码:
#include<iostream>
using namespace std;
int main ()
{
cout<<"------------------------------------"<<endl;
cout<<"Province Area(km2) Pop.(10K)"<<endl;
cout<<"------------------------------------"<<endl;
cout<<"Anhui 139600.00 6461.00"<<endl;
cout<<"Beijing 16410.54 1180.70"<<endl;
cout<<"Chongqing 82400.00 3144.23"<<endl;
cout<<"Shanghai 6340.50 1360.26"<<endl;
cout<<"Zhejiang 101800.00 4894.00"<<endl;
cout<<"------------------------------------"<<endl;
return 0;
}
7-6:混合类型数据格式化输入
1.题目:
2.源码:
#include<iostream>
using namespace std;
int main ()
{
char a;
int b;
float c,d;
scanf("%f %d %c %f",&c,&b,&a,&d);
printf("%c %d %.2f %.2f",a,b,c,d);
return 0;
}
7-7:12-24小时制
1.题目:
2.源码:
#include<iostream>
using namespace std;
int main ()
{
int hour,min;
scanf("%d:%d",&hour,&min);
if(hour>=0&&hour<12)
printf("%d:%d AM",hour,min);
if(hour==12)
printf("12:%d PM",min);
if(hour>12)
printf("%d:%d PM",hour-12,min);
return 0;
}
7-8:超速判断
1.题目:
2.源码:
#include<iostream>
using namespace std;
int main ()
{
int spe;
cin>>spe;
if(spe<=60)
printf("Speed: %d - OK",spe);
else
printf("Speed: %d - Speeding",spe);
return 0;
}
7-9:用天平找小球
1.题目:
2.源码:
#include<iostream>
using namespace std;
int main ()
{
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
if(a==b)
printf("C");
if(a==c)
printf("B");
if(b==c)
printf("A");
return 0;
}
//注意输出的字母为大写
7-10:计算工资
1.题目:
2.源码:
#include<iostream>
using namespace std;
int main ()
{
int year,time;
float sum;
scanf("%d %d",&year,&time);
if(year>=5)
{
if(time<=40)
sum=50*time;
else
sum=50*40+1.5*50*(time-40);
}
else
{
if(time<=40)
sum=30*time;
else
sum=30*40+30*1.5*(time-40);
}
printf("%.2f",sum);
return 0;
}
7-11:分段计算居民水费
1.题目:
2.源码:
#include<iostream>
using namespace std;
int main ()
{
float x,y;
cin>>x;
if(x<=15)
y=(4*x)/3;
else
y=2.5*x-17.5;
printf("%.2f",y);
return 0;
}
7-12:两个数的简单计算器
1.题目:
2.源码:
#include<iostream>
using namespace std;
int main ()
{
int a,b;
char c;
scanf("%d %c %d",&a,&c,&b);
if(c=='+')
printf("%d",a+b);
else if(c=='-')
printf("%d",a-b);
else if(c=='*')
printf("%d",a*b);
else if(c=='/')
printf("%d",a/b);
else if(c=='%')
printf("%d",a%b);
else
printf("ERROR");
return 0;
}
7-13:日K蜡烛图
1.题目:
2.源码:
#include<iostream>
using namespace std;
int main ()
{
float open,high,low,close;
scanf("%f %f %f %f",&open,&high,&low,&close);
//如果Close<Open,表示为“BW-Solid”(即“实心蓝白蜡烛”);
if(close<open)
{
if((low<open&&low<close)&&(high>open&&high>close))
printf("BW-Solid with Lower Shadow and Upper Shadow");
else if(high>open&&high>close)
printf("BW-Solid with Upper Shadow");
else if(low<open&&low<close)
printf("BW-Solid with Lower Shadow");
else
printf("BW-Solid");
}
//如果Close>Open,表示为“R-Hollow”(即“空心红蜡烛”);
if(close>open)
{
if(low<open&&low<close)
printf("R-Hollow with Lower Shadow");
else if(high>open&&high>close)
printf("R-Hollow with Upper Shadow");
else if((low<open&&low<close)&&(high>open&&high>close))
printf("R-Hollow with Lower Shadow and Upper Shadow");
else
printf("R-Hollow");
}
//如果Open等于Close,则为“R-Cross”(即“十字红蜡烛”)。
if(open==close)
{
if(low<open&&low<close)
printf("R-Cross with Lower Shadow");
else if(high>open&&high>close)
printf("R-Cross with Upper Shadow");
else if((low<open&&low<close)&&(high>open&&high>close))
printf("R-Cross with Lower Shadow and Upper Shadow");
else
printf("R-Cross");
}
return 0;
}
7-14:求整数段和
1.题目:
2.源码:
#include<iostream>
using namespace std;
int main ()
{
int a,b,k=0,ret=0,sum=0;
scanf("%d %d",&a,&b);
for(int i=a;i<=b;i++)
{
printf("%5d",i);
k++;
if(k%5==0)
{
cout<<endl;
}
sum+=i;
}
if (k % 5 != 0)
{
cout << endl;
printf("Sum = %d", sum);
}
else
printf("Sum = %d",sum);
return 0;
}