1. 角谷猜想
#include <iostream>
using namespace std;
int main()
{
long n;
cin >> n;
while(n>1)
{
if(n%2==0) {
cout << n << "/2=";
n /= 2;
} else {
cout << n << "*3+1=";
n = n*3+1;
}
cout << n << endl;
}
cout << "End" << endl;
return 0;
}
考点很奇怪!n 为 long 类型
2. 正常血压
#include <iostream>
using namespace std;
int main()
{
int n, a, b;
int cnt = 0;
int max = 0;
cin >> n;
for(int i=0; i<n; i++)
{
cin >> a >> b;
if (90 <=a && a <= 140 && 60 <=b && b <= 90) {
cnt++;
max = (cnt>max)?cnt:max;
} else {
cnt = 0;
}
}
cout << max << endl;
return 0;
}
4
100 80
90 50
120 60
140 90
2
4
0 0
0 0
0 0
0 0
0
4
100 80
0 0
100 80
0 0
1
4
100 80
100 80
100 80
0 0
3
3. 数字反转
#include <iostream>
using namespace std;
int main()
{
long long n;
int zero = 0;
cin >> n;
if (n<0)
{
n = -n;
cout << '-';
}
while(n>=10)
{
int m = n%10;
if (m != 0)
zero = 1;
if (zero != 0 || m != 0)
cout << m;
n /= 10;
}
cout << n << endl;
return 0;
}
123
321
-380
-83
0
0
1
1
1000
1
-10
-1
4. 求特殊自然数
#include <iostream>
using namespace std;
int main()
{
int n;
for (int i=0;i<=6;i++) {
for (int j=0;j<=6;j++) {
for (int k=0;k<=6;k++) {
n = i*7*7+j*7+k;
if (n != 0 && n == k*9*9+j*9+i) {
cout << n << endl;
cout << i << j << k << endl;
cout << k << j << i << endl;
}
}
}
}
return 0;
}
5. 雇佣兵
#include <iostream>
using namespace std;
int main()
{
int M,N,X,a;
cin >> M >> N >> X;
while (X>0 && M>=N)
{
a = M/N;
X -= (M % N != 0)?(a+1):a;
if (X<0) break;
N += a;
}
cout << N << endl;
return 0;
}
5 2 10
6
2 5 10
5
2 2 10
3
3 2 1
2
3 2 2
3
6. 数字统计
#include <iostream>
using namespace std;
int main()
{
int A,B;
int n=0;
cin >> A >> B;
for (;A<=B;A++)
{
int i=A;
while(i>0)
{
if(i%10==2) n++;
i/=10;
}
}
cout << n << endl;
return 0;
}
2 22
6
2 100
20
1 1
0
1 2
1
-eof-