#include<iostream>
#include<string>
#include<fstream>
#include<algorithm>
using namespace std;
struct Student{
unsigned long long int ID;
string name;
bool sex;
unsigned short int grade[3];
};
Student *ReadArray(int &RecordNum)
{
int temp;
ifstream infile;
infile.open("学生成绩表");
if (infile==0) return 0;
infile>>RecordNum;
Student *p=new Student [RecordNum];
Student *head=p;
for (int i=0;i<RecordNum;i++)
{
infile>>temp;
infile>>p->ID;
infile>>p->name;
infile>>p->sex;
for (int j=0;j<3;j++)
infile>>p->grade[j];
p++;
}
infile.close();
return head;
}
void Show(Student a[],int num)
{
int sn=1;
for (int i=0;i<num;i++)
{
cout<<sn++<<" ";
cout<<a[i].ID<<" "<<a[i].name<<" ";
if (a[i].sex) cout<<" 男"<<" ";
else cout<<" 女"<<" ";
for (int j=0;j<3;j++)
cout<<" "<<a[i].grade<<" ";
cout<<endl;
}
}
int cmp(const void *a,const void *b)
{return (*(Student*)a).grade[2]-(*(Student*)b).grade[2];}
bool myGreater(Student &elem1,Student &elem2)
{
return (elem1.grade[2]>elem2.grade[2]);
}
int main()
{
int N;
Student *A;
A=ReadArray(N);
if (A==0) {cout<<"文件打开失败·!\n";return 0;}
cout<<"序号"<<"t\学号"<<"\t 姓名"<<"性别"<<"高数"<<"英语"<<"C++"<<endl;
Show(A,N);
cout<<"用qsort函数对c++进行排升序"<<endl;
qsort(A,N,sizeof(*A),cmp);
Show(A,N);
sort(A,A+N,myGreater);
Show(A,N);
delete[]A;
system("pause");
return 0;
#include<string>
#include<fstream>
#include<algorithm>
using namespace std;
struct Student{
unsigned long long int ID;
string name;
bool sex;
unsigned short int grade[3];
};
Student *ReadArray(int &RecordNum)
{
int temp;
ifstream infile;
infile.open("学生成绩表");
if (infile==0) return 0;
infile>>RecordNum;
Student *p=new Student [RecordNum];
Student *head=p;
for (int i=0;i<RecordNum;i++)
{
infile>>temp;
infile>>p->ID;
infile>>p->name;
infile>>p->sex;
for (int j=0;j<3;j++)
infile>>p->grade[j];
p++;
}
infile.close();
return head;
}
void Show(Student a[],int num)
{
int sn=1;
for (int i=0;i<num;i++)
{
cout<<sn++<<" ";
cout<<a[i].ID<<" "<<a[i].name<<" ";
if (a[i].sex) cout<<" 男"<<" ";
else cout<<" 女"<<" ";
for (int j=0;j<3;j++)
cout<<" "<<a[i].grade<<" ";
cout<<endl;
}
}
int cmp(const void *a,const void *b)
{return (*(Student*)a).grade[2]-(*(Student*)b).grade[2];}
bool myGreater(Student &elem1,Student &elem2)
{
return (elem1.grade[2]>elem2.grade[2]);
}
int main()
{
int N;
Student *A;
A=ReadArray(N);
if (A==0) {cout<<"文件打开失败·!\n";return 0;}
cout<<"序号"<<"t\学号"<<"\t 姓名"<<"性别"<<"高数"<<"英语"<<"C++"<<endl;
Show(A,N);
cout<<"用qsort函数对c++进行排升序"<<endl;
qsort(A,N,sizeof(*A),cmp);
Show(A,N);
sort(A,A+N,myGreater);
Show(A,N);
delete[]A;
system("pause");
return 0;
}
public class Example3_1{
public staic void main(String args[])
char a1='中',char a2='国',a3='科',a4='大';
char secret='A';
a1=(char)(a1^secret);
a2=(char)(a2^secret);
a3=(char)(a3^secret);
a4=(char)(a4^secret);
System.out.println("密文"+a1+a2+a3+a4);
a1=(char)(a1^secret);
a2=(char)(a2^secret);
a3=(char)(a3^secret);
a4=(char)(a4^secret);
System.out.println("原文"+a1+a2+a3+a4);
}
}
(wrong)