问题描述:
问题解析:
问题的本质就是求输入数据/2。
编程问题(C++语言或C语言):
1.多输入数据怎么读取?
2.多输出数据怎么显示?
C++语言:
#include#include #include #include using namespace std; int main() { int n; while (cin >> n && n != 0 && n >= 1 && n <= 100) { int a = n / 2; cout << a << endl; } return 0; }
C语言:
#include#include #include #include using namespace std; int main(void) { int i, n; int j = 0; int a[10] = { 0 }; while (scanf_s("%d", &n) != EOF && n != 0) { a[j++] = n; } for (i = 0; i < 10&&a[i]!=0; i++) printf("%dn", a[i]/2); return 0;
python语言:
方法1:
import sys
pyin = [int(i) for i in sys.stdin.read().split()]
for n in pyin:
z_num = 0
if n == 0:
exit();
if n > 100 and n < 0:
exit();
kong = n
while kong // 3:
yu = kong % 3
zheng = kong // 3
z_num += zheng
kong = yu + zheng
if kong % 3 == 2:
z_num += 1
print(z_num)
方法2:
import sys
inpy = [int(i) for i in sys.stdin.read().split()]
for i in inpy:
if i == 0:
break
print(i // 2)
方法3:
int getValid(int number)
{
int x=0;
int y=0;
int rtn=0;
if(number == 1)
{
return 0;
}
else if(number == 2)
{
return 1;
}
else
{
x=number%3;
y=number/3;
rtn = y;
rtn += getValid(x+y);
return rtn;
}
}
void main (void)
{
int num,result=0;
while(scanf("%d",&num)&&(num!=0))
{
result = getValid(num);
printf("%dn",result);
}
}



