508 条题解
-
0bamzy LV 4 @ 2014-08-23 13:32:23
###Block code
#include <stdio.h>char stu[110][30];
int n;
int sch[110];int main() {
int i, k, t;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s %d %d %c %c %d", stu[i] + 5, &stu[i][0], &stu[i][1], &stu[i][2], &stu[i][3], &t);
stu[i][4] = t + 1;
}
for (i = 0; i < n; i++) {
if (stu[i][0] > 80 && stu[i][4] > 1) sch[i] += 8000;
if (stu[i][0] > 85 && stu[i][1] > 80) sch[i] += 4000;
if (stu[i][0] > 90) sch[i] += 2000;
if (stu[i][0] > 85 && stu[i][3] == 'Y') sch[i] += 1000;
if (stu[i][1] > 80 && stu[i][2] == 'Y') sch[i] += 850;
}
k = 0;
for (i = 1; i < n; i++)
if (sch[i] > sch[k])
k = i;
printf("%s\n%d\n", stu[k] + 5, sch[k]);
for (i = 0, k = 0; i < n; i++)
k += sch[i];
printf("%d\n", k);
return 0;
} -
02014-08-18 18:07:20@
#include <iostream>
#include <string>
#ifdef DEBUG
#include <fstream>
#endif
using namespace std;
class Student
{
public:
string name;
int qm;
int bj;
string gb;
string xb;
int paper;
int getScholar()
{
int sum = 0;if((qm > 80) && (paper > 0))
sum += 8000;if((qm > 85) && (bj > 80))
sum += 4000;if(qm > 90)
sum += 2000;if((qm > 85) && (xb == "Y"))
sum += 1000;if((bj > 80) && (gb == "Y"))
sum += 850;return sum;
}
};
int main()
{
#ifdef DEBUG
#define INPUT input
ifstream input;
input.open("data.txt");
#else
#define INPUT cin
#endif
int N;
INPUT >> N;
Student* t = new Student[N];
int Mmoney(0), Smoney(0);
string Mname;for(int i = 0; i < N; i++)
{
INPUT >> t[i].name >> t[i].qm >> t[i].bj >> t[i].gb >> t[i].xb >> t[i].paper;if(t[i].getScholar() > Mmoney)
{
Mmoney = t[i].getScholar();
Mname = t[i].name;
}Smoney += t[i].getScholar();
}cout << Mname << endl;
cout << Mmoney << endl;
cout << Smoney << endl;
delete [] t;
#ifdef DEBUG
input.close();
#endifreturn 0;
} -
02014-08-10 12:52:24@
###Block bode
type data=record
names:string;
qimo:0..100;
pingyi:0..100;
ganbu:boolean;
xibu:boolean;
lunwen:0..10;
jiangxuejin:longint;
end;var x:array[1..100] of data;
i,n,pos,sum:longint;
t:char;begin
readln(n);
for i:=1 to n do
with x[i] do
begin
read(t);
while t<>' ' do
begin
names:=names+t;
read(t);
end;
read(qimo,pingyi);
read(t);
read(t);
if t='Y' then
ganbu:=true;
read(t);
read(t);
if t='Y' then
xibu:=true;
readln(lunwen);
if (qimo>80) and (lunwen>0) then
inc(jiangxuejin,8000);
if (qimo>85) and (pingyi>80) then
inc(jiangxuejin,4000);
if qimo>90 then
inc(jiangxuejin,2000);
if (qimo>85) and xibu then
inc(jiangxuejin,1000);
if (pingyi>80) and ganbu then
inc(jiangxuejin,850);
end;
pos:=1;
sum:=x[1].jiangxuejin;
for i:=2 to n do
with x[i] do
begin
if jiangxuejin>x[pos].jiangxuejin then
pos:=i;
inc(sum,jiangxuejin);
end;
writeln(x[pos].names);
writeln(x[pos].jiangxuejin);
writeln(sum);
end. -
02014-08-10 12:50:52@
type data=record
names:string;
qimo:0..100;
pingyi:0..100;
ganbu:boolean;
xibu:boolean;
lunwen:0..10;
jiangxuejin:longint;
end;var x:array[1..100] of data;
i,n,pos,sum:longint;
t:char;begin
readln(n);
for i:=1 to n do
with x[i] do
begin
read(t);
while t<>' ' do
begin
names:=names+t;
read(t);
end;
read(qimo,pingyi);
read(t);
read(t);
if t='Y' then
ganbu:=true;
read(t);
read(t);
if t='Y' then
xibu:=true;
readln(lunwen);
if (qimo>80) and (lunwen>0) then
inc(jiangxuejin,8000);
if (qimo>85) and (pingyi>80) then
inc(jiangxuejin,4000);
if qimo>90 then
inc(jiangxuejin,2000);
if (qimo>85) and xibu then
inc(jiangxuejin,1000);
if (pingyi>80) and ganbu then
inc(jiangxuejin,850);
end;
pos:=1;
sum:=x[1].jiangxuejin;
for i:=2 to n do
with x[i] do
begin
if jiangxuejin>x[pos].jiangxuejin then
pos:=i;
inc(sum,jiangxuejin);
end;
writeln(x[pos].names);
writeln(x[pos].jiangxuejin);
writeln(sum);
end. -
02014-08-09 18:30:04@
C++ 无文件版本 AC
a数组多余,是为了其他可能出现的情况而存在,可精简。#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
const int maxn=101;
typedef struct
{
string name;
int score_exam,score_class;
char sir,west;
int essay;
int scholar,num;
}student;
int main()
{
student a[maxn];
int n,sum=0;
cin>>n;
string ans;
int max=0;
for(int i=1;i<=n;i++)
{
a[i].scholar=0; a[i].num=i;
cin>>a[i].name>>a[i].score_exam>>a[i].score_class>>a[i].sir>>a[i].west>>a[i].essay;
if(a[i].score_exam>80 && a[i].essay>=1) a[i].scholar+=8000;
if(a[i].score_exam>85 && a[i].score_class>80) a[i].scholar+=4000;
if(a[i].score_exam>90) a[i].scholar+=2000;
if(a[i].score_exam>85 && a[i].west=='Y') a[i].scholar+=1000;
if(a[i].score_class>80 && a[i].sir=='Y') a[i].scholar+=850;
sum+=a[i].scholar;
if(a[i].scholar>max)
{
ans=a[i].name;
max=a[i].scholar;
}
}
cout<<ans<<endl<<max<<endl<<sum;
return 0;
} -
02014-08-02 23:40:13@
3wa
原因:
细节问题
主要是变量以及数组的初始化问题
其中计算单个学生奖金的ans没有初始化
字符数组更新之前未初始化,以至于cout>>s,后面还残留有之前的值
-
02014-07-27 21:35:31@
#include <iostream>
#include <string>
#ifdef DEBUG
#include <fstream>
#endif
using namespace std;
class Student {
public:
string name;
int qm;
int bj;
string gb;
string xb;
int paper;
int getScholar() {
int sum = 0;
if((qm>80)&&(paper>0))
sum+=8000;
if((qm>85)&&(bj>80))
sum+=4000;
if(qm>90)
sum+=2000;
if((qm>85)&&(xb=="Y"))
sum+=1000;
if((bj>80)&&(gb=="Y"))
sum+=850;
return sum;
}
};
int main() {
#ifdef DEBUG
#define INPUT input
ifstream input;
input.open("data.txt");
#else
#define INPUT cin
#endif
int N;
INPUT>>N;
Student* t = new Student[N];
int Mmoney(0),Smoney(0);
string Mname;
for(int i = 0;i<N;i++) {
INPUT>>t[i].name>>t[i].qm>>t[i].bj>>t[i].gb>>t[i].xb>>t[i].paper;
if(t[i].getScholar()>Mmoney) {
Mmoney = t[i].getScholar();
Mname = t[i].name;
}
Smoney += t[i].getScholar();
}
cout<<Mname<<endl;
cout<<Mmoney<<endl;
cout<<Smoney<<endl;
delete [] t;
#ifdef DEBUG
input.close();
#endifreturn 0;
} -
02014-07-27 21:35:13@
面向对象的思路
#include <iostream>
#include <string>
#ifdef DEBUG
#include <fstream>
#endif
using namespace std;
class Student {
public:
string name;
int qm;
int bj;
string gb;
string xb;
int paper;
int getScholar() {
int sum = 0;
if((qm>80)&&(paper>0))
sum+=8000;
if((qm>85)&&(bj>80))
sum+=4000;
if(qm>90)
sum+=2000;
if((qm>85)&&(xb=="Y"))
sum+=1000;
if((bj>80)&&(gb=="Y"))
sum+=850;
return sum;
}
};
int main() {
#ifdef DEBUG
#define INPUT input
ifstream input;
input.open("data.txt");
#else
#define INPUT cin
#endif
int N;
INPUT>>N;
Student* t = new Student[N];
int Mmoney(0),Smoney(0);
string Mname;
for(int i = 0;i<N;i++) {
INPUT>>t[i].name>>t[i].qm>>t[i].bj>>t[i].gb>>t[i].xb>>t[i].paper;
if(t[i].getScholar()>Mmoney) {
Mmoney = t[i].getScholar();
Mname = t[i].name;
}
Smoney += t[i].getScholar();
}
cout<<Mname<<endl;
cout<<Mmoney<<endl;
cout<<Smoney<<endl;
delete [] t;
#ifdef DEBUG
input.close();
#endifreturn 0;
} -
02014-07-26 19:59:22@
program p16;
var a,b:string;
e,f,i,j:longint;
d:char;function js(var a2:string):longint;
var cost,b2,b3,b4,b5,b6,b7,b8:longint; {qi mo pingjun chengji:b4}
c1,c2,c3:char; {c1:gb c2:west}
a3:string; {banji ping yi chengji:b5 b6:lun wen shu}
begin
cost:=0;
b8:=0;
b2:=1;
repeat
b2:=b2+1;
until ord(a2[b2])=32;
b2:=b2+1;
b3:=b2;
while (ord(a2[b3])<>32) do b3:=b3+1;
a3 := copy(a2, b2, b3-b2);
val(a3,b4,b8);
b3 := b3+1;
b2:=b3;
while (ord(a2[b3])<>32) do b3 := b3 +1;
a3 := copy(a2,b2,b3-b2);
val(a3,b5,b8);
b3:=b3+1;
c1:=a2[b3];
c2:=a2[b3+2];
b3:=b3+4;
b2:=b3;
if (ord(a2[b3+1])=48) then begin
a3 := copy(a2,b3,2);
val(a3,b6,b8);
end
else begin
a3 := copy(a2,b3,1);
val(a3,b6,b8);
end;
if (b5>80)and(c1='Y') then cost := cost+850;
if (b4>85)and(c2='Y') then cost := cost+1000;
if (b4>90) then cost := cost+2000;
if (b4>85)and(b5>80) then cost := cost+4000;
if (b4>80)and(b6>=1) then cost := cost+8000;
js := cost;
end;
begin
readln(e);
readln(a);
f:=f+js(a);
for j := 2 to e do begin
readln(b);
f:=f+js(b);
if js(b)>js(a) then a := b;
end;
j := 1;
while ord(a[j])<>32 do begin
write(a[j]);
j:=j+1;
end;
writeln;
writeln(js(a));
write(f);
end. -
02014-07-20 22:45:49@
C++标准题解
#include <string>
#include <cstdlib>
#include <iostream>
using namespace std;
struct info{
string name;
int examScore;
int classScore;
char ganbu;
char xibu;
int lecture;
};
struct result{
string name;
int count;
int sum;
};
void input(info info[], int N)
{
for(int i = 0; i < N; ++i)
std::cin>>info[i].name>>info[i].examScore>>info[i].classScore>>info[i].ganbu>>info[i].xibu>>info[i].lecture;
}
void output(result re)
{std::cout<<re.name<<endl;
std::cout<<re.count<<endl;
std::cout<<re.sum<<endl;
}
void cul(info std[],int N)
{
int oldCount = 0,newCount = 0,sum = 0;
int pos = -1;
for(int i = 0; i < N; ++i)
{
newCount = 0;if(std[i].examScore > 90)
{
newCount +=2000;
sum += 2000;
}
if(std[i].examScore > 80 && std[i].lecture > 0)
{
newCount +=8000;
sum +=8000;
}
if(std[i].examScore > 85 && std[i].classScore > 80)
{
newCount +=4000;
sum +=4000;
}
if(std[i].examScore > 85 && std[i].xibu == 'Y')
{
newCount +=1000;
sum +=1000;
}
if(std[i].classScore > 80 && std[i].ganbu == 'Y')
{
newCount +=850;
sum +=850;
}
if(oldCount < newCount)
{
oldCount = newCount;
pos = i;}
}
result re;
re.name = std[pos].name;
re.count = oldCount;
re.sum = sum;
output(re);}
int main(int argc, char** argv)
{
int N;
std::cin>>N;
if(N < 1 || N > 100)
return -1;
info std[N];
input(std,N);
cul(std,N);return 0;
} -
02014-07-18 17:26:43@
#include<cstdio>
#include<iostream>
#include<string>
int q[101],j[101],l[101],jiang[101];
using namespace std;
main()
{
int a,n,i,k,c,z;
scanf("%d",&n);
char x[101],s[101];
string b[101];
for(i=1;i<=n;++i)
{
cin>>b[i];
scanf(" %d",&q[i]);
scanf(" %d",&j[i]);
cin>>x[i]>>s[i];
scanf(" %d",&l[i]);
}
for(k=1;k<=n;++k)
{
jiang[k]=0;
}
for(i=1;i<=n;++i)
{
if((q[i]>80)&&(l[i]>=1))
{
jiang[i]+=8000;
}
if((q[i]>85)&&(j[i]>80))
{
jiang[i]+=4000;
}
if(q[i]>90)
{
jiang[i]+=2000;
}
if((q[i]>85)&&(s[i]=='Y'))
{
jiang[i]+=1000;
}
if((j[i]>80)&&(x[i]=='Y'))
{
jiang[i]+=850;
}
}
z=0;
for(k=1;k<=n;++k)
{
z+=jiang[k];
}
c=1;
a=jiang[1];
for(i=2;i<=n;++i)
{
if(jiang[i]>a)
{
a=jiang[i];
c=i;
}
}
cout<<b[c]<<endl;
printf("%d\n",a);
printf("%d",z);
return 0;
} -
02014-07-10 15:38:53@
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int qm[101],bj[101],gb[101],xb[101],lw[101];
int w[101]={0};
string s[101];
main()
{
int n,i,j,sum=0,max=0,best;
char a,b;
cin>>n;
for(i=1;i<=n;++i)
{
cin>>s[i]>>qm[i]>>bj[i];
cin>>a>>b;
gb[i]=(a=='Y')?1:0;
xb[i]=(b=='Y')?1:0;
cin>>lw[i];
if((qm[i]>80)&&(lw[i]))w[i]+=8000;
if((qm[i]>85)&&(bj[i]>80))w[i]+=4000;
if(qm[i]>90)w[i]+=2000;
if((qm[i]>85)&&(xb[i]))w[i]+=1000;
if((bj[i]>80)&&(gb[i]))w[i]+=850;
}
for(j=1;j<=n;++j)
{
sum+=w[j];
if(max<w[j])
{
max=w[j];
best=j;
}
}
cout<<s[best]<<endl<<max<<endl<<sum;
return 0;
} -
02014-07-10 12:36:31@
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <time.h>
#include <string.h>using namespace std;
struct geren{
char name[32];
int qm;
int bj;
char gb;
char xb;
int lw;
int sum;
int sh;
};geren a[101];
int main(int argc,char *argv[])
{
int i,j,k,n,m;
cin>>n;
for(i=0;i<n;i++)
{
cin>>a[i].name>>a[i].qm>>a[i].bj>>a[i].gb>>a[i].xb>>a[i].lw;
a[i].sum=0;
a[i].sh=i;
}
k=0;
for(i=0;i<n;i++)
{
if(a[i].qm>80 && a[i].lw>0)
{
a[i].sum+=8000;
k+=8000;
}
if(a[i].qm>85 && a[i].bj>80)
{
a[i].sum+=4000;
k+=4000;
}
if(a[i].qm>90)
{
a[i].sum+=2000;
k+=2000;
}
if(a[i].qm>85 && a[i].xb=='Y')
{
a[i].sum+=1000;
k+=1000;
}
if(a[i].bj>80 && a[i].gb=='Y')
{
a[i].sum+=850;
k+=850;
}
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[j].sum>a[i].sum)
swap(a[i],a[j]);
}
}
j=a[0].sh;
m=0;
for(i=1;i<n;i++)
{
if(a[i].sum==a[0].sum)
{
if(a[i].sh<j)
{
j=a[i].sh;
m=i;
}
}
}
cout<<a[m].name<<endl;
cout<<a[m].sum<<endl;
cout<<k<<endl;
// system("pause");
return 0;
} -
02014-06-29 20:43:17@
n=int(raw_input())
a,ans=[],[]
tot,totans=0,0
for i in range(n):
a=raw_input().split(' ')
now=0
if int(a[1])>80 and int(a[5]):
now=now+8000
if int(a[1])>85 and int(a[2])>80:
now=now+4000
if int(a[1])>90:
now=now+2000
if int(a[1])>85 and a[4]=='Y':
now=now+1000
if int(a[2])>80 and a[3]=='Y':
now=now+850
tot=tot+now
if totans<now:
totans=now
ans=a
print ans[0]
print totans
print tot -
02014-06-08 10:00:11@
var n:integer;
a:array[1..100]of string;
b:array[1..100,1..2]of integer;
c:array[1..100]of char;
d:array[1..100]of char;
e:array[1..100]of integer;
sum:array[1..100]of longint;
i:integer;
max,maxs,s:longint;
ch,k:char;
begin
readln(n);
fillchar(sum,sizeof(sum),0);
for i:=1 to n do begin
a[i]:='';
repeat
read(ch);
if ch<>' ' then a[i]:=a[i]+ch;
until ch=' ';
readln(b[i,1],b[i,2],k,c[i],k,d[i],e[i]);
if (b[i,1]>80) and(e[i]>=1)then inc(sum[i],8000);
if (b[i,1]>85) and(b[i,2]>80)then inc(sum[i],4000);
if (b[i,1]>90) then inc(sum[i],2000);
if (b[i,1]>85) and(d[i]='Y')then inc(sum[i],1000);
if (b[i,2]>80) and(c[i]='Y')then inc(sum[i],850);
end;
maxs:=0;
for i:=1 to n do if sum[i]>maxs then begin
max:=i;
maxs:=sum[i];
end;
writeln(a[max]);
writeln(sum[max]);
s:=0;
for i:=1 to n do inc(s,sum[i]);
writeln(s);
end. -
02014-06-07 16:49:03@
#include<stdio.h>
struct
{char name[50];
int jun;
int yi;
char xg;
char xx;
int num;
int jing;
}stu[320];
int main()
{freopen("ex1.in","r",stdin);
freopen("ex1.out","w",stdout);
int i,n,b=1;
long max,sum=0;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%s %d %d %c %c %d",stu[i].name,&stu[i].jun,&stu[i].yi,&stu[i].xg,&stu[i].xx,&stu[i].num);
stu[i].jing=0;
}
for(i=1;i<=n;i++)
{
if(stu[i].jun>80 && stu[i].num>=1)stu[i].jing+=8000;
if(stu[i].jun>85 && stu[i].yi>80) stu[i].jing+=4000;
if(stu[i].jun>90) stu[i].jing+=2000;
if(stu[i].jun>85 && stu[i].xx=='Y')stu[i].jing+=1000;
if(stu[i].yi>80 && stu[i].xg=='Y')stu[i].jing+=850;
}
max=stu[1].jing;b=1;
for(i=1;i<=n;i++)
{
if(max<stu[i].jing){max=stu[i].jing;b=i;}
sum=sum+stu[i].jing;
}
printf("%s\n%d\n%ld",stu[b].name,stu[b].jing,sum);
return 0;
}
-
02014-05-13 22:49:31@
#include <stdio.h>
typedef struct
{
char name[18]; //姓名
int end_grade; //期末平均成绩
int class_grade; //班级评议成绩
char ganbu; //学生干部 Y/N
char xibu; //西部学生 Y/N
int lunwen; //论文数量 1~10
int all; //奖金总额
}Student;int index; //保存奖金最大的学生下标
int temp; //交换变量
int total; //存储所有学生奖金总额
Student stu[100];void fun(Student *student, int i); //计算该学生的奖金额和统计所有学生的奖金总额,并判断哪个学生奖金额最高
int main()
{
int i=0;
scanf("%d", &i); //输入第i个学生信息
while (i)
{
scanf("%s %d %d %c %c %d", &stu[i].name, //格式字符s,d,c分别表示 字符串、带符号的整形数、字符等
&stu[i].end_grade,
&stu[i].class_grade,
&stu[i].ganbu,
&stu[i].xibu,
&stu[i].lunwen);
fun(&stu[i], i);
--i; //输入的学生数到达i个后,跳出循环
} //打印获奖金数最多的学生姓名、该生所获奖金数、全部学生所获奖金数
printf("%s\n%d\n%d\n", stu[index].name, stu[index].all, total);
}
void fun(Student *student, int i)
{(*student).all = 0;
//班级贡献奖
if ((*student).class_grade > 80 && (*student).ganbu == 'Y' )
{
(*student).all += 850;
}
//五四奖学金
if ((*student).class_grade > 80 && (*student).end_grade > 85 )
{
(*student).all += 4000;
}
//院士奖学金
if ((*student).end_grade > 80 && (*student).lunwen >= 1)
{
(*student).all += 8000;
}
//成绩优秀奖
if ((*student).end_grade > 90)
{
(*student).all += 2000;
}
//西部奖学金
if ((*student).end_grade > 85 && (*student).xibu == 'Y')
{
(*student).all += 1000;
}total += (*student).all; //统计所有学生的总金额
if (temp < (*student).all) //判断哪个学生奖金额最高
{
temp = (*student).all; //把该生最高奖金额数赋给temp
index = i; //保存奖金最大的学生下标
}
} -
02014-05-07 00:09:56@
#include <iostream>
#include <string>
using namespace std;class Student
{
public:
string name;
int final,class_,count,prize;
char sir,west;
Student(){};
Student(string a,int b,int c,char d,char e,int f)
{
name=a;
final=b;
class_=c;
sir=d;
west=e;
count=f;
prize=0;
}
int getPrize() const
{
int p=0;
if(final>80&&count>=1) p+=8000;
if(final>85&&class_>80) p+=4000;
if(final>90) p+=2000;
if(final>85&&west=='Y') p+=1000;
if(class_>80&&sir=='Y') p+=850;return p;
}Student& operator = (Student it)
{
name=it.name;
final=it.final;
class_=it.class_;
sir=it.sir;
west=it.west;
count=it.count;
}
void display() const
{
cout<< name << " " << this->getPrize() <<endl;
}
};
int main()
{
int t;
cin>> t;
Student haha[100];string name;
int final,class_,count;
char sir,west;int index=0,n=t;
while(n--)
{
cin>> name >> final >> class_ >> sir >> west >> count;
haha[index]=Student(name,final,class_,sir,west,count);
++index;
}int sum=0,high=0,ans=0;
for(int i=0; i<t; ++i)
{
int key=haha[i].getPrize();
if(key>high)
{
ans=i;
high=key;
}
sum+=key;
}cout<< haha[ans].name <<endl;
cout<< haha[ans].getPrize() <<endl;
cout<< sum <<endl;return 0;
} -
02014-04-27 17:47:15@
pascaler 哪错了?请看这个:
-
02014-04-26 18:35:10@
var i,j,k,l,n,m,ans1,max:longint;
student:array[0..1000] of record
name:string;
score:longint;
classes:longint;
carde:string[2];
west:string[2];
article:longint;
money:longint;
end;
c:char;
ans:string;
begin
readln(n);
for i:=1 to n do
with student[i] do begin
name:='';
c:='a';
while c<>' ' do begin
read(c);
if c<>' ' then name:=name+c;
end;
read(score);
read(classes);
read(carde);
read(west);
readln(article);
if (score>80) and (article>=1) then money:=money+8000;
if (score>85) and (classes>80) then money:=money+4000;
if (score>90) then money:=money+2000;
if (score>85) and (west=' Y') then money:=money+1000;
if (classes>80) and (carde=' Y') then money:=money+850;
if money>max then begin
max:=money;
ans:=name;
end;
ans1:=ans1+money;
end;
writeln(ans);
writeln(max);
writeln(ans1);
end.
哪错了?(pascal)