2000 ASCII码排序
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
char a, b, c;
while (cin >> a >> b >> c) {
char sum = a + b + c;
char maxx = max(max(a,b),c);
char minn = min(min(a,b),c);
char mid = sum - maxx - minn;
cout << minn << ' ' << mid << ' ' << maxx << endl;
}
return 0;
}
#include <stdio.h>
#include <string.h>
int main()
{
char a, b, c;
while (scanf("%c %c %c",&a,&b,&c)!=EOF) {
getchar();
char t;
if (a > b) {
t = a;
a = b;
b = t;
}
if (a > c) {
t = a;
a = c;
c = t;
}
if (b > c) {
t = b;
b = c;
c = t;
}
printf("%c %c %c\n",a,b,c);
}
return 0;
}
2001 计算两点间的距离 sqrt(),pow() math.h
#include <stdio.h>
#include <math.h>
int main()
{
double x1, x2, y1, y2;
double sum = 0;
while (scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2)!=EOF) {
sum = sqrt(pow(x1 - x2,2) + pow(y1 - y2,2));
printf("%.2lf\n",sum);
}
return 0;
}
2002 计算球体积
#include <stdio.h>
#include <math.h>
#define PI 3.1415927
int main()
{
double r;
double are;
while (scanf("%lf",&r)!=EOF) {
are = (double)4/3 * PI * pow(r,3);
printf("%.3lf\n",are);
}
return 0;
}
2003 求绝对值
#include <stdio.h>
int main(){
double x;
while ((scanf("%lf", &x))!= EOF)
printf("%.2f\n", (x > 0) ? x : -x);
return 0;
}
int,abs()函数在头文件“stdlib.h”中,浮点,fabs()函数在头文件“math.h”中 想试试c++行不行
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
double a;
while (cin >> a) {
printf("%.2f\n", fabs(a));
}
return 0;
}
2004 成绩转换
#include <iostream>
using namespace std;
int main()
{
double t;
while (cin >> t) {
if (t >= 90 && t <= 100) {
cout << 'A' << endl;
} else if (t >= 80 && t <= 89) {
cout << 'B' << endl;
} else if (t >= 70 && t <= 79) {
cout << 'C' << endl;
} else if (t >= 60 && t <= 69) {
cout << 'D' << endl;
} else if (t >= 0 && t <= 59) {
cout << 'E' << endl;
} else {
cout << "Score is error!" << endl;
}
}
return 0;
}
2005 第几天?
#include <iostream>
using namespace std;
int main()
{
int year, month, day;
while (cin >> year >> month >> day) {
int m[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
m[1] = 29;
}
int sum = 0;
for (int i = 0; i < month - 1; ++i) {
sum += m[i];
}
sum += day;
cout << sum << endl;
}
return 0;
}
2006 求奇数的乘积
#include <iostream>
using namespace std;
int main()
{
int n;
int num;
while (cin >> n) {
int sum = 1;
while (n--) {
cin >> num;
if (num % 2 != 0) {
sum *= num;
}
}
cout << sum << endl;
}
return 0;
}
2007 平方和与立方和 一直没找到哪里错输入的哪一个大是不确定的
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int n, m;
while (cin >> n >> m) {
if (n > m) {
int temp = m;
m = n;
n = temp;
}
int x = 0, y = 0;
for (int i = n; i <= m; ++i) {
if (i % 2 != 0) {
y += (pow(i,3));
} else {
x += (i*i);
}
}
cout << x << ' ' << y << endl;
}
return 0;
}
2008 数值统计
#include <iostream>
using namespace std;
int main()
{
int n;
while (cin >> n,n!=0) {
int a = 0, b = 0, c = 0;
while (n--) {
double num;
cin >> num;
if (num < 0) {
++a;
} else if (num > 0) {
++b;
} else {
++c;
}
}
cout << a << ' ' << c << ' ' << b << endl;
}
return 0;
}
2009 求数列的和
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
double m, n;
while (cin >> m >> n) {
double sum = 0;
for (int i = 0; i < n; ++i) {
sum += m;
m = sqrt(m);
}
printf("%.2lf\n",sum);
}
return 0;
}
2010 水仙花数
#include <iostream>
#include <math.h>
using namespace std;
bool iswf(int num) {
int a, b , c;
a = num / 100;
b = num / 10 % 10;
c = num % 10;
if (pow(a,3)+ pow(b,3) + pow(c,3) == num) {
return true;
}
return false;
}
int main()
{
int m, n;
while (cin >> m >> n) {
int flag = 1;
for (int i = m; i <= n; ++i) {
if (iswf(i)) {
if (flag == 1) {
cout << i;
} else {
cout << ' ' << i;
}
flag = 0;
}
}
if (flag == 0) {
cout << endl;
} else {
cout << "no" << endl;
}
}
return 0;
}
2011 多项式求和 单精度浮点数用f,双精度浮点数用lf(printf可混用,但scanf不能混用)
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
while (n--) {
int num;
double sum = 0;
cin >> num;
for (int i = 1; i <= num; ++i) {
if (i % 2 == 0) {
sum -= 1.0/i;
} else {
sum += 1.0/i;
}
}
printf("%.2lf\n",sum);
}
return 0;
}
2039 三角形
#include <iostream>
using namespace std;
int main()
{
int m;
cin >> m;
double a, b, c;
while (m--) {
cin >> a >> b >> c;
if (a + b > c && a + c > b && b + c > a) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
return 0;
}
|