这是关于UVa在线评判问题的链接.
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=29&page=show_problem&problem=1078
我的C代码是
#include <stdio.h>
double avg(double * arr,int students)
{
int i;
double average=0;
for(i=0;i<students;i++){
average=average+(*(arr+i));
}
average=average/students;
int temp=average*100;
average=temp/100.0;
return average;
}
double mon(double * arr,int students,double average)
{
int i;
double count=0;
for(i=0;i<students;i++){
if(*(arr+i)<average){
double temp=average-*(arr+i);
int a=temp*100;
temp=a/100.0;
count=count+temp;
}
}
return count;
}
int main(void)
{
// your code goes here
int students;
scanf("%d",&students);
while(students!=0){
double arr[students];
int i;
for(i=0;i<students;i++){
scanf("%lf",&arr[i]);
}
double average=avg(arr,students);
//printf("%lf\n",average);
double money=mon(arr,students,average);
printf("$%.2lf\n",money);
scanf("%d",&students);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
其中一个输入和输出是 …
我问这个只是为了澄清我的想法是否正确。
静态/动态类型 如果在编译时变量的类型是已知的,则语言是静态类型的。这实际上意味着您作为程序员必须指定每个变量的类型。示例:Java、C、C++。
如果在运行时解释变量的类型,则语言是动态类型化的。这意味着您作为程序员可以更快地编写代码,因为您不必每次都指定类型。示例:Perl
Static/Dynamic Binding——下面的链接清楚地解释了Static Binding和Dynamic Binding的区别
我想问的主要问题从这里开始。我知道静态范围和动态范围之间的区别。然而,当我经历堆栈溢出时,人们说 C++ 和 Python 是静态作用域的。
在 C++ 中,如果我输入
int void main(){
cout<<i;
int i=15;
}
int i=10;
Run Code Online (Sandbox Code Playgroud)
它可以工作(即使在 java 中)。但是它的 python 等价物
def foo():
print(x)
x=10
x='global'
foo()
Run Code Online (Sandbox Code Playgroud)
给出一个错误。