
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
char **fileList = 0
int n
unsigned long *id = 0
unsigned long c = 0
void File ( char *name )
{
int i, j, min
char *s
c++
for ( i = 0i <n &&fileList[i]!= 0i++ )
if ( !strcmp ( name, fileList[i] ) )
{
id[i] = c
return
}
if ( fileList[n-1] == 0 )
{
for ( i = n-1i >= 0 &&fileList[i] == 0i-- )
i++
}
else
{
min = *idj = 0
for ( i = 1i <ni++ )
{
if ( min >id[i] )
{
min = id[i]
j = i
}
}
free ( fileList[j] )
while ( ++j <配逗 n )
{
fileList[j-1] = fileList[j]
id[j-1] = id[j]
}
i = n - 1
}
s = (char*)malloc ( strlen(name) + 1 )
strcpy ( s, name )
fileList[i] = s
id[i] = c
return
}
void empty ( void )
{
int i
for ( i = 0i <n &&fileList[i][0] != 0i++ )
{
puts ( fileList[i] )
free ( fileList[i] )
}
}
int main ( void )
{
char line[1024], *p = line+2
gets ( line )
sscanf ( line+2, "%d", &n )
fileList = (char**) malloc ( (n)<<2 )
id = (unsigned long*) malloc ( n<<培旁卖启携2 )
memset ( fileList, 0, (n)<<2 )
while ( 1 )
{
gets ( line )
if ( *line == '!' )break
File ( p )
}
empty()
free ( fileList )
free ( id )
}
第一题看的脑壳疼,但是和第二题的意思差不多,我帮你做了第二题
public class List {public static void main(String[] args) {
Employee e1 = new Employee("张强","2010/09/01",6890)
e1.show("普通")
System.out.println("年纳税:"+e1.tax())
Manager m1 = new Manager("朱慧","2003/07/06",18530,38000)
m1.show("管理")
System.out.println("年咐旁纳税:"+m1.tax())
}
}
//下面仿简丛是补全的代码
class Employee{
String name,date
double salary,bonus
Employee(String name,String date,double salary){
this.name = name
this.date = date
this.salary = salary
}
public void show(String str){
System.out.println("岗位:"+str)
System.out.println("姓名:"+name+",入职时间:"+date+",月薪:"+salary)
}
public double tax(){
if(salary <= 0){
throw new RuntimeException("工资不允许小于等于0")
}
else if(salary>3000 && salary<=5000){
salary = salary*0.05*12 //纳税这里我也不知道他们具体是怎么个算法,反正意思差不多,套进去就行了
}
else if(salary>5000 && salary<=10000){
salary = salary*0.1*12
}
else if(salary>10000 && salary<=15000){
salary = salary*0.15*12
}
else if(salary>15000){
salary = salary*0.2*12
}
return salary+(bonus*0.2)
}
}
class Manager extends Employee{
Manager(String name,String 备樱date,double salary,double bonus){
super(name,date,salary)
super.bonus = bonus
}
public void show(String str){
System.out.println("岗位:"+str)
System.out.println("姓名:"+name+",入职时间:"+date+",月薪:"+salary+",奖金:"+bonus)
}
}
#include<stdio.h>#include<string.h>
#include<malloc.h>
typedef struct stu //一个学生的档案
{
char num[20]//学号
char name[20]//姓名
float score[5]//成大裂绩,前三门是单科成绩,第四个是总分,最后一个是平均分
}student
student s[10]//所有学生的信息
void main()
{
void init()//初始化函数申明
void sort()//排序函数申明
void print()//输出函数申明
init()
sort()
print()
}
void init()//初始化所有学生的档案
{
int i,j
for(i=0i<10i++) //逐个键入学生的信息
{
printf("请输入一学生的学号:")
scanf("%s",s[i].num)
printf("请输入该学生的姓名:"锋亏)
scanf("%s",s[i].name)
printf("请输入该学生的三门成绩:")
s[i].score[3]=0
for(j=0j<3j++)
{
scanf("%f",&s[i].score[j])
s[i].score[3]+=s[i].score[j]//求总分
}
s[i].score[4]=s[i].score[3]/3//求平均分
}
printf("学生档案建立成功!\n")
}
void sort()
{
int i,j,k
char str[20]
float temp
for(i=0i<9i++) //主循环,进行排名
for(j=i+1j<10j++)
if(s[j].score[3]>s[i].score[3])
{
strcpy(str,s[i].num)//交换学号
strcpy(s[i].num,s[j].num)
strcpy(s[j].num,str)
strcpy(str,s[i].name)//交换姓名
strcpy(s[i].name,s[j].name)
strcpy(s[j].name,str)
for(k=0k<5k++) //交换成绩
{
temp=s[i].score[k]
s[i].score[k]=s[j].score[k]
s[j].score[k]=temp
}
}
}
void print()
{
int i
for(i=0i<滚基闭10i++)
printf("%s %s %.1f %.1f %.1f %.1f %.1f\n",s[i].num,s[i].name,s[i].score[0],s[i].score[1],s[i].score[2],s[i].score[3],s[i].score[4]
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)