T1015——输出保留12位小数的浮点数**********
代码如下——
#include<iostream>
using namespace std;
char str[20];
int main(void)
{
str[0] = '?';
int len = 1;
for (int i = 1; i < 16; ++i)
{
char ch = getchar();
if (ch == '\n')break;
str[i] = ch;
len++;
}
if (len - 3 >= 13)
{
int jin = 0;
if (str[15] >= '5')
{
jin = 1;
}
for (int i = 14; i >= 1; --i)
{
char ch = (((str[i] - '0') + jin) % 10) + '0';
jin = ((str[i] - '0') + jin) / 10;
str[i] = ch;
}
if (jin != 0)
{
str[0] = '1';
for (int i = 0; i < len; ++i)
{
cout << str[i];
}
}
else
{
for (int i = 1; i < len - 1; ++i)
{
cout << str[i];
}
}
}
else
{
for (int i = 1; i < len; ++i)
{
cout << str[i];
}
for (int i = 0; i < 12 - (len - 3);++i)
{
cout << '0';
}
}
return 0;
}
运行结果如下——
如果我们用c语言会更简单——(四舍六入五看双)
#include<iostream>
using namespace std;
int main(void)
{
long double x;
scanf("%llf", &x);
printf("%.12llf", x);
return 0;
}
T1780——时间转换
代码如下——
#include<iostream> using namespace std; int main(void) { int h, m, s; cin>>s; m = s / 60; s = s % 60; h = m / 60; m = m % 60; cout<<h<<":"<<m<<":"<<s; return 0; }
运行结果如下——
T1027——大象喝水
代码如下——
#include<iostream>
#include<cmath>
using namespace std;
const double pai = 3.14159;
int main()
{
int l = 20 * 1000;
int h, r;
cin >> h >> r;
cout<< ceil(l/(pai * r * r * h));
return 0;
}
运行结果如下——
T1028——苹果与虫子
代码如下——
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
double n, x, y; cin >> n >> x >> y;
cout << floor(n - (y / x));
return 0;
}
运行结果如下——
T1025——计算浮点数相除的余数
代码如下——
T1029——计算2的幂(用位运算求解)
代码如下——
#include<iostream>
using namespace std;
int main()
{
int n; cin >> n ;
cout <<(1<<n);
return 0;
}
运行结果如下——
T1038——判断能否被3,5,7整除(标记法)
代码如下——
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int num; cin >> num;
bool flag = false;
if (num % 3 == 0)
{
cout << 3 << " ";
flag = true;
}
if (num % 5 == 0)
{
cout << 5 << " ";
flag = true;
}
if (num % 7 == 0)
{
cout << 7 << " ";
flag = true;
}
if (flag == false)
{
cout << "n" << endl;
}
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int num; cin >> num;
bool flag = false;
if (num % 3 == 0)cout << 3 << " ",flag = true;
if (num % 5 == 0)cout << 5 << " ",flag = true;
if (num % 7 == 0)cout << 7 << " ",flag = true;
if (flag == false)cout << "n" << endl;
return 0;
}
运行结果如下——
T1039——小蒜蒜的成绩
代码如下——
#include<iostream>
using namespace std;
int main()
{
int a, b; cin >> a >> b;
if ((a < 60 && b >= 60) || (b < 60 && a >= 60)) cout << 1 << endl;
else cout << 0 << endl;
return 0;
}
运行结果如下——