508 条题解
-
0puyuxuan LV 6 @ 2018-04-05 08:09:58
其实运用结构体来做很好理解,代码如下:
#include<iostream> #include<string> using namespace std; struct jiang //定义每个人的结构体 { string name; int qi,ban,lun; char gan,sheng; int s; }; int main() { int x; cin>>x; jiang n[x]; for(int i=0;i<x;i++) { cin>>n[i].name; cin>>n[i].qi; cin>>n[i].ban; cin>>n[i].gan; cin>>n[i].sheng; cin>>n[i].lun; } //读入每个人的信息 for(int i=0;i<x;i++) { n[i].s=0; if(n[i].qi>80&&n[i].lun>=1) n[i].s+=8000; if(n[i].qi>85&&n[i].ban>80) n[i].s+=4000; if(n[i].qi>90) n[i].s+=2000; if(n[i].qi>85&&n[i].sheng=='Y') n[i].s+=1000; if(n[i].ban>80&&n[i].gan=='Y') n[i].s+=850; } //判断每个人是否得到各个奖学金 long max=-1,ss=0; for(int i=0;i<x;i++) { ss+=n[i].s; if(n[i].s>max) max=n[i].s; } //找最大值并累加和 for(int i=0;i<x;i++) { if(n[i].s==max) { cout<<n[i].name<<endl; cout<<n[i].s<<endl; cout<<ss; return 0; } //输出 } return 0; }
-
02018-04-03 20:40:46@
#include <iostream>
using namespace std;
int main()
{
int N;
int a,b,i,amax;
amax=0;
cout<<"the number of student:";
cin>>N;
if(N>=100&&N<0)
cout<<"cin error";
cout<<endl<<"name scoreOfLast scoreOfClass class west numberOfarticle";
cout<<endl;
char name[N];
int LastScore[N],classScore[N],numeberOfareticle[N];
int yuanshi=8000,wusi=4000,chengji=2000,xibu=1000,banji=850,allmoney[N];
char classn[N],west[N];
for(i=0;i<N;i++)
{ /*cin number*/
allmoney[i]=0;
cin>>name[i]>>LastScore[i]>>classScore[i]>>classn[i]>>west[i]>>numeberOfareticle[i];
/*the number of allmoney*/
if(classScore[i]>80)
{ if(classn[i]='Y')
allmoney[i]+=banji;
if(LastScore[i]>85)
allmoney[i]+=wusi;
}
if(LastScore[i]>90)
allmoney[i]+=chengji;
else if(LastScore[i]>85)
{
if(west[i]='Y')
allmoney[i]+=xibu;
}
else if(LastScore[i]>80&&numeberOfareticle[i]>=1)
allmoney[i]+=yuanshi;
}
/*compare the number*/
for(i=0;i<N;i++)
{
if(allmoney[i]>amax)
{
amax=allmoney[i];
a=i;
}
}
/*compute the number of allmoney*/
for(i=0;i<N;i++)
{
b+=allmoney[i];
}
/*cout*/
cout<<name[a]<<endl;
cout<<allmoney[a]<<endl;
cout<<b<<endl;
} -
02018-03-25 18:34:00@
没什么好说的,直接**暴力**
#include<bits/stdc++.h> using namespace std ; //Vijos P1001 int n , num1 , num2 , num3 , ans2 , ans3 , result ; char name[20] , ans1[20] , judge1 , judge2 ; int money1()//院士奖学金 { return ((num1 > 80) && (num3 >= 1)) ? 8000 : 0 ; } int money2()//五四奖学金 { return ((num1 > 85) && (num2 > 80)) ? 4000 : 0 ; } int money3()//成绩优秀奖 { return num1 > 90 ? 2000 : 0 ; } int money4()//西部奖学金 { return ((num1 > 85) && (judge2 == 'Y')) ? 1000 : 0 ; } int money5()//班级贡献奖 { return ((num2 > 80) && (judge1 == 'Y')) ? 850 : 0 ; } int main() { cin >> n ; for (int i = 0 ; i < n ; i ++) { cin >> name >> num1 >> num2 >> judge1 >> judge2 >> num3 ; result = money1() + money2() + money3() + money4() + money5() ; if (ans2 < result)//ans2是获得奖学金最多的人获得的奖学金 { for (int j = 0 ; j <= strlen(name) ; j ++)//个人习惯,不太喜欢用string,只能一个一个记录,不过也能过 { ans1[j] = name[j] ; } ans2 = result ; } ans3 += result ; } cout << ans1 << endl << ans2 << endl << ans3 ; }
-
02018-02-28 15:44:02@
#include<bits/stdc++.h> using namespace std; struct student { char name[100+10]; int all; int banji; char ganbu; char xibu; int lunwen; int money=0; }; struct student a[1000+10],name,all,banji,ganbu,xibu,lunwen;//定义结构体 int main() { int n,i,j,t,s; s=0; cin>>n; for(i=1;i<=n;i++) { cin>>a[i].name>>a[i].all>>a[i].banji>>a[i].ganbu>>a[i].xibu>>a[i].lunwen;//输入各项资料 if(a[i].all>80 && a[i].lunwen>=1) a[i].money=a[i].money+8000;//奖项一 if(a[i].all>85 && a[i].banji>80) a[i].money=a[i].money+4000;//奖项二 if(a[i].all>90) a[i].money=a[i].money+2000;//奖项三 if(a[i].all>85 && a[i].xibu=='Y') a[i].money=a[i].money+1000;//奖项四 if(a[i].banji>80 && a[i].ganbu=='Y') a[i].money=a[i].money+850; //奖项五 s=s+a[i].money; } for(i=1;i<=n;i++) for(j=1;j<=n-1;j++) if(a[j].money<a[j+1].money) swap(a[j],a[j+1]);//比较钱数多少(冒泡排序) for(i=1;i<=1;i++) cout<<a[i].name<<endl<<a[i].money<<endl<<s; return 0; }
-
02018-02-12 10:29:17@
。。
-
02018-02-06 15:45:28@
#include<cstdio>
#include<iostream>
using namespace std;
main()
{
int n;
scanf("%d",&n);
int j=n+10;
string name[j];
char gb[j],xb[j];
float cj[j],bp[j];
int lw[j];
for(int i=1;i<=n;i++)
{
cin>>name[i];
scanf("%f%f %c %c%d",&cj[i],&bp[i],&gb[i],&xb[i],&lw[i]);
}
int pj[n+2];
for(int i=1;i<=n;i++)
{
pj[i]=0;
if(cj[i]>90) pj[i]+=2000; //成绩优秀奖
if(cj[i]>85&&bp[i]>80) pj[i]+=4000; //五四奖学金
if(cj[i]>80&&lw[i]>=1) pj[i]+=8000; //院士奖学金
if(cj[i]>85&&xb[i]=='Y') pj[i]+=1000; //西部奖学金
if(bp[i]>80&&gb[i]=='Y') pj[i]+=850; //班级贡献奖
}
int max=1;
int sum=0;
for(int i=1;i<=n;i++)
{
max=pj[i]>pj[max]?i:max;
sum+=pj[i];
}
cout<<name[max]<<endl;
printf("%d\n%d",pj[max],sum);
return 0;
} -
02018-02-03 10:22:55@
为什么不用结构体呢?
#include<bits/stdc++.h>
using namespace std;
char xn[20];
struct{
char name[20];
int m;
int cl;
char gb;
char xb;
int lw;
int s;
}a[110];
int main(){
int n,i,max,zc=0;
cin>>n;
for(i=1;i<=n;i++)
a[i].s=0;
for(i=1;i<=n;i++){
scanf("%s",a[i].name);
cin>>a[i].m>>a[i].cl>>a[i].gb>>a[i].xb>>a[i].lw;
}
for(i=1;i<=n;i++){
if(a[i].m>80&&a[i].lw>=1){
a[i].s+=8000;
zc+=8000;
}
if(a[i].m>85&&a[i].cl>80){
a[i].s+=4000;
zc+=4000;
}
if(a[i].m>90){
a[i].s+=2000;
zc+=2000;
}
if(a[i].m>85&&a[i].xb=='Y'){
a[i].s+=1000;
zc+=1000;
}
if(a[i].cl>80&&a[i].gb=='Y'){
a[i].s+=850;
zc+=850;
}
}
max=a[1].s;
for(i=1;i<=n;i++)
if(a[i].s>max){
max=a[i].s;
strcpy(xn,a[i].name);
}
puts(xn);
cout<<max<<endl;
cout<<zc;
return 0;
} -
02018-02-03 10:07:29@
#include <bits/stdc++.h>
using namespace std;
struct{
char name[30];
int qc,bc,lw,xj,s;
char xg,xb;
}a[110],t;
int main(){
int n,i,zjq=0,j,max,p;
cin>>n;
for(i=1;i<=n;i++)
cin>>a[i].name>>a[i].qc>>a[i].bc>>a[i].xg>>a[i].xb>>a[i].lw;a[i].s=0;
for(i=1;i<=n;i++){
if(a[i].qc>80&&a[i].lw>0)
a[i].s=a[i].s+8000;
if(a[i].qc>85&&a[i].bc>80)
a[i].s=a[i].s+4000;
if(a[i].qc>90)
a[i].s=a[i].s+2000;
if(a[i].qc>85&&a[i].xb==89)
a[i].s=a[i].s+1000;
if(a[i].bc>80&&a[i].xg==89)
a[i].s=a[i].s+850;
}
max=a[1].s;
p=1;
for(i=1;i<=n;i++){
if(max<a[i].s){
max=a[i].s;
p=i;
}
zjq=zjq+a[i].s;
}
cout<<a[p].name<<endl;
cout<<max<<endl;
cout<<zjq<<endl;
return 0;
} -
02018-02-02 13:27:52@
#include <iostream>
#include<string>
#include<stdlib.h>
using namespace std;
struct students
{
string na;
int count;
};
void bubble(students* st, int n)
{
int i = n - 1;
while (i > 0)
{
int pos = 0;
for (int j = 0; j < i; j++)
{
if (st[j].count < st[j + 1].count)
{
pos = j;
students temp = st[j];
st[j] = st[j + 1];
st[j + 1] = temp;
}
}
i = pos;
}
}
int main()
{
int N;
cin >> N;
students* st = new students[N];
string a;//姓名
int b;//期末平均成绩
int c;//班级评议成绩
char d;//是否学生干部
char e;//是否西部省份学生
int f;//论文数量
for(int i=0;i<N;i++)
{
cin >> a >> b>> c >> d>> e>> f;
st[i].na = a;
st[i].count = 0;
if (b > 80 && f >= 1)
{
st[i].count = st[i].count + 8000;
}
if (b > 85 && c > 80)
{
st[i].count = st[i].count + 4000;
}
if (b > 90)
{
st[i].count = st[i].count + 2000;
}
if (b > 85 && e == 'Y')
{
st[i].count = st[i].count + 1000;
}
if (c > 80 && d == 'Y')
{
st[i].count = st[i].count + 850;
}
}
bubble(st, N);
int h = 0;
for (int i = 0; i < N; i++)
h = h + st[i].count;
cout << st[0].na << endl;
cout << st[0].count << endl;
cout << h;
system("pause");
return 0;
} -
02018-01-31 21:05:59@
输入控制符加空格
#include<bits/stdc++.h> #include<string.h> int main(){ int n,max=-1,maxn,fnl[101],cls[101],work[101],west[101],paper[101],money[101]={0}; char name[101][101]; memset(name,0,sizeof(name)); scanf("%d",&n); for(int i=1;i<=n;++i){ scanf("%s %d %d %c %c %d",name[i],&fnl[i],&cls[i],&work[i],&west[i],&paper[i]); if((fnl[i]>80)&&(paper[i]>0)) money[i]=money[i]+8000; if((fnl[i]>85)&&(cls[i]>80)) money[i]=money[i]+4000; if(fnl[i]>90) money[i]=money[i]+2000; if((fnl[i]>85)&&(west[i]=='Y')) money[i]=money[i]+1000; if((cls[i]>80)&&(work[i]=='Y')) money[i]=money[i]+850; if(money[i]>max){ max=money[i]; maxn=i; } money[0]=money[0]+money[i]; } printf("%s\n%d\n%d",name[maxn],max,money[0]); }
-
02018-01-31 14:40:44@
难点只有一个
5) 班级贡献奖,每人850元,班级评议成绩高于80分(>80)的学生干部均可获得;
import java.util.Scanner; public class Main { static class Student { private String name; private int finalGrade; private int classGrade; private boolean classCadre; private boolean fromWest; private int paper; private int totalPrice; } public static void main(String[] args) { Scanner scan = new Scanner(System.in); int count = scan.nextInt(); int allTotal = 0; Student bestStudent = new Student(); Student student = null; for (int i = 0; i < count; i++) { student = new Main.Student(); student.name = scan.next(); student.finalGrade = scan.nextInt(); student.classGrade = scan.nextInt(); student.classCadre = "Y".equalsIgnoreCase(scan.next()); student.fromWest = "Y".equalsIgnoreCase(scan.next()); student.paper = scan.nextInt(); getTotal(student); allTotal += student.totalPrice; if (student.totalPrice > bestStudent.totalPrice) { bestStudent = student; } } scan.close(); System.out.println(bestStudent.name); System.out.println(bestStudent.totalPrice); System.out.println(allTotal); } public static void getTotal(Student student) { int finalGrade = student.finalGrade; if (finalGrade > 90) { student.totalPrice += 2000; } if (finalGrade > 85) { if (student.classGrade > 80) { student.totalPrice += 4000; } if (student.fromWest) { student.totalPrice += 1000; } } if (finalGrade > 80 && student.paper > 0) { student.totalPrice += 8000; } if (student.classCadre && student.classGrade > 80) { student.totalPrice += 850; } } }
-
02018-01-28 13:23:48@
package ZJ1;
import java.util.Scanner;
public class ZJ1_2_jiangxuejin {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan=new Scanner(System.in);
int stuNum=scan.nextInt();
String StuInfor[][]=new String[stuNum][6];
int jiangxuejin[]=new int[stuNum];
int total=0;
for(int i=0;i<stuNum;i++)
jiangxuejin[i]=0;
for(int i=0;i<stuNum;i++){
for(int j=0;j<6;j++){
StuInfor[i][j]=scan.next();
}
if(Integer.parseInt(StuInfor[i][1])>80&&Integer.parseInt(StuInfor[i][5])>0)
jiangxuejin[i]+=8000;
if(Integer.parseInt(StuInfor[i][1])>85&&Integer.parseInt(StuInfor[i][2])>80)
jiangxuejin[i]+=4000;
if(Integer.parseInt(StuInfor[i][1])>90)
jiangxuejin[i]+=2000;
if(Integer.parseInt(StuInfor[i][1])>85&&StuInfor[i][4].equals("Y"))
jiangxuejin[i]+=1000;
if(Integer.parseInt(StuInfor[i][2])>80&&StuInfor[i][3].equals("Y"))
jiangxuejin[i]+=850;
}
for(int i=0;i<stuNum;i++){
total+=jiangxuejin[i];
}
int maxJXJ=jiangxuejin[0];
int maxIndex=0;
for(int i=0;i<stuNum;i++){
if(jiangxuejin[i]>maxJXJ){
maxJXJ=jiangxuejin[i];
maxIndex=i;
}
}
System.out.println(StuInfor[maxIndex][0]);
System.out.println(jiangxuejin[maxIndex]);
System.out.println(total);
}}
-
02018-01-28 11:25:30@
@xueyouchao,你开始输出1个“"input student num:”是干什么,你删掉试一试
-
02018-01-28 11:19:17@
#include<iostream>
using namespace std;
struct xuesheng{
string mingzi;
int qmcj,bjjycj,lunwen,jiangxuejin;
char ganbu,xibu;
};
int main(){
int a,i,zuidazhi,he=0,weizhi=0;
cin>>a;
xuesheng b[a];
for(i=0;i<a;i++){
cin>>b[i].mingzi>>b[i].qmcj>>b[i].bjjycj>>b[i].ganbu>>b[i].xibu>>b[i].lunwen;
b[i].jiangxuejin=0;
if(b[i].qmcj>80&&b[i].lunwen>=1){
b[i].jiangxuejin+=8000;
}
if(b[i].qmcj>85&&b[i].bjjycj>80){
b[i].jiangxuejin+=4000;
}
if(b[i].qmcj>90){
b[i].jiangxuejin+=2000;
}
if(b[i].qmcj>85&&b[i].xibu=='Y'){
b[i].jiangxuejin+=1000;
}
if(b[i].bjjycj>80&&b[i].ganbu=='Y'){
b[i].jiangxuejin+=850;
}
}
zuidazhi=b[0].jiangxuejin;
for(i=1;i<a;i++){
if(b[i].jiangxuejin>zuidazhi){
zuidazhi=b[i].jiangxuejin;
weizhi=i;
}
}
cout<<b[weizhi].mingzi<<endl<<zuidazhi<<endl;
for(i=0;i<a;i++){
he+=b[i].jiangxuejin;
}
cout<<he;
return 0;
} -
02018-01-24 01:49:27@
#include<stdio.h>
#include<string.h>
int fk(int a,int b,char c,char d,int e){
int sum=0;
if(a>80&&e>=1)sum+=8000;
if(a>85&&b>80)sum+=4000;
if(a>90)sum+=2000;
if(a>85&&d=='Y')sum+=1000;
if(b>80&&c=='Y')sum+=850;
return sum;
}
int main(){
int i,j,n,a,b,e,max=0,sum=0;
char c,d;
char numa[25];
char maxname[25];
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%s %d %d %c %c %d",&numa,&a,&b,&c,&d,&e);
sum+=fk(a,b,c,d,e);
if(max<fk(a,b,c,d,e)){
strcpy(maxname,numa);
max=fk(a,b,c,d,e);
}
}
printf("%s\n%d\n%d",maxname,max,sum);
return 0;
} -
02018-01-24 01:49:18@
#include<stdio.h>
#include<string.h>
int fk(int a,int b,char c,char d,int e){
int sum=0;
if(a>80&&e>=1)sum+=8000;
if(a>85&&b>80)sum+=4000;
if(a>90)sum+=2000;
if(a>85&&d=='Y')sum+=1000;
if(b>80&&c=='Y')sum+=850;
return sum;
}
int main(){
int i,j,n,a,b,e,max=0,sum=0;
char c,d;
char numa[25];
char maxname[25];
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%s %d %d %c %c %d",&numa,&a,&b,&c,&d,&e);
sum+=fk(a,b,c,d,e);
if(max<fk(a,b,c,d,e)){
strcpy(maxname,numa);
max=fk(a,b,c,d,e);
}
}
printf("%s\n%d\n%d",maxname,max,sum);
return 0;
} -
02018-01-14 10:07:33@
#include<iostream>
#include<string>int main(){
std::string a,g;
int qimo,banjipinyi,n,lunwen,monny=0,result=0,sum=0;
char xibu,ganbu;
std::cin >> n;
for(int i=0;i<n;i=i+1){
std::cin >> a >> qimo >> banjipinyi >> ganbu >> xibu >> lunwen;
monny=0;
if(qimo>80&&lunwen>=1){
monny=monny+8000;
}
if(qimo>85&&banjipinyi>80){
monny=monny+4000;
}
if(qimo>90){
monny=monny+2000;
}
if(qimo>85&&xibu=='Y'){
monny=monny+1000;
}
if(banjipinyi>80&&ganbu=='Y'){
monny=monny+850;
}
if(monny>result){
g=a;
result=monny;
}
sum=monny+sum;
}
std::cout << g << std::endl << result << std::endl << sum << std::endl;
return 0;
} -
02018-01-14 10:07:17@
#include<iostream>
#include<string>int main(){
std::string a,g;
int qimo,banjipinyi,n,lunwen,monny=0,result=0,sum=0;
char xibu,ganbu;
std::cin >> n;
for(int i=0;i<n;i=i+1){
std::cin >> a >> qimo >> banjipinyi >> ganbu >> xibu >> lunwen;
monny=0;
if(qimo>80&&lunwen>=1){
monny=monny+8000;
}
if(qimo>85&&banjipinyi>80){
monny=monny+4000;
}
if(qimo>90){
monny=monny+2000;
}
if(qimo>85&&xibu=='Y'){
monny=monny+1000;
}
if(banjipinyi>80&&ganbu=='Y'){
monny=monny+850;
}
if(monny>result){
g=a;
result=monny;
}
sum=monny+sum;
}
std::cout << g << std::endl << result << std::endl << sum << std::endl;
return 0;
} -
02018-01-06 23:05:28@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
struct student
{
char name[20];
int qscore;
int bscore;
char bangan;
char xibu;
int lunwen;
int z;}stu[100];
int main()
{
int n,i,j=0,k=0;
struct student temp;
char ch;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%s %d %d %c %c %d",stu[i].name,&stu[i].qscore,&stu[i].bscore,&stu[i].bangan,&stu[i].xibu,&stu[i].lunwen);
stu[i].z=0;
if(stu[i].qscore>80&&stu[i].lunwen>=1)
stu[i].z=stu[i].z+8000;
if(stu[i].bscore>80&&stu[i].qscore>85)
stu[i].z=stu[i].z+4000;
if(stu[i].qscore>90)
stu[i].z=stu[i].z+2000;
if(stu[i].xibu=='Y'&&stu[i].qscore>85)
stu[i].z=stu[i].z+1000;
if(stu[i].bangan=='Y'&&stu[i].bscore>80)
stu[i].z=stu[i].z+850;
k=k+stu[i].z;
}
for(i=0;i<n-1;i++)
{
for(j=0;j<n-1;j++)
{
if(stu[j].z<stu[j+1].z)
{
temp=stu[j];
stu[j]=stu[j+1];
stu[j+1]=temp;
}
}
}
temp=stu[0];
for(i=1;stu[i].z==temp.z&&i<n;i++)
{
if(strcmp(stu[i].name,temp.name)<0)
temp=stu[i];
}
printf("%s\n%d\n%d",temp.name,temp.z,k);
return 0;
} -
02018-01-03 13:58:38@
python3 的老铁们嘿嘿嘿:
N=int(input())
sum_get=int(0)
fir_stu=[' ',int(0)]
while N!=0:
N-=1
massage=input().split()
a_get=int(0)
if int(massage[1])>int(80) and int(massage[5])>=int(1):
a_get+=int(8000)
if int(massage[1])>int(85) and int(massage[2])>int(80):
a_get+=int(4000)
if int(massage[1])>int(90):
a_get+=int(2000)
if int(massage[1])>int(85) and massage[4]=='Y':
a_get+=int(1000)
if int(massage[2])>int(80) and massage[3]=='Y':
a_get+=int(850)
if a_get>fir_stu[1]:
fir_stu[0]=massage[0]
fir_stu[1]=int(a_get)
sum_get+=a_get
print(str(fir_stu[0]))
print(int(fir_stu[1]))
print(int(sum_get))
print('')