presentation error
在一个论坛上做题,改了半天老是presentation error,望高手指正刚刚忘了贴网址……http://yzfy.org/dis/listpost.php?tid=186&extra=page%3D1&page=1
程序代码:
import java.util.*;
public class Main {
public static void main(String[] args) {
int n,k;
Scanner scan = new Scanner(System.in);
while(scan.hasNext()){
n = scan.nextInt();
k = scan.nextInt();
int[][] temp = new int[n][k];
int[] sum = new int[n];
for(int i = 0; i < temp.length; i++){
for (int j = 0; j < temp[0].length; j++){
temp[i][j] = scan.nextInt();
sum[i] += temp[i][j];
}
}
int [] average = new int[k];
for (int i = 0; i < temp[0].length; i++){
for (int j = 0; j < temp.length; j++ )
average[i] += temp[j][i];
}
for (int i = 0; i < sum.length; i++)
System.out.print(sum[i] + " ");
System.out.println();
double a;
for (int i = 0; i < average.length; i++){
a = average[i]/(double)n;
if(a * 10 % 10 < 5)
System.out.print((int)a + " ");
else
System.out.print((int)(a +1) + " ");
}
System.out.println();
System.out.println();
}
}
}
public class Main {
public static void main(String[] args) {
int n,k;
Scanner scan = new Scanner(System.in);
while(scan.hasNext()){
n = scan.nextInt();
k = scan.nextInt();
int[][] temp = new int[n][k];
int[] sum = new int[n];
for(int i = 0; i < temp.length; i++){
for (int j = 0; j < temp[0].length; j++){
temp[i][j] = scan.nextInt();
sum[i] += temp[i][j];
}
}
int [] average = new int[k];
for (int i = 0; i < temp[0].length; i++){
for (int j = 0; j < temp.length; j++ )
average[i] += temp[j][i];
}
for (int i = 0; i < sum.length; i++)
System.out.print(sum[i] + " ");
System.out.println();
double a;
for (int i = 0; i < average.length; i++){
a = average[i]/(double)n;
if(a * 10 % 10 < 5)
System.out.print((int)a + " ");
else
System.out.print((int)(a +1) + " ");
}
System.out.println();
System.out.println();
}
}
}
[ 本帖最后由 heartnheart 于 2010-2-21 22:22 编辑 ]
搜索更多相关的解决方案:
presentation
----------------解决方案--------------------------------------------------------
50分没人要吗?O(∩_∩)O~
----------------解决方案--------------------------------------------------------
程序代码:
import java.math.*;
class nn{
public static void n1(String a[]){
int s1=a[0].split(",").length;
int ret1[]=new int[a.length];
int ret2[]=new int[s1];
for(int s=0;s<a.length;s++){
String b1[]= a[s].split(",");
for(int ss=0;ss<s1;ss++){
ret1[s]+=Integer.parseInt(b1[ss]);
ret2[ss]+=Integer.parseInt(b1[ss])/a.length;
}
}
pr(ret1);
pr(ret2);
}
public static void pr(int a[]){
String s$="";
for(int i=0;i<a.length;i++){
s$+=a[i]+" ";
}
System.out.println(s$);
}
}
public class aa{
public static void main(String args[]){
String a[]={"100,100","90,90","80,80"};
String b[]={"90,90,90","60,60,60"};
nn.n1(a);
nn.n1(b);
}
}
class nn{
public static void n1(String a[]){
int s1=a[0].split(",").length;
int ret1[]=new int[a.length];
int ret2[]=new int[s1];
for(int s=0;s<a.length;s++){
String b1[]= a[s].split(",");
for(int ss=0;ss<s1;ss++){
ret1[s]+=Integer.parseInt(b1[ss]);
ret2[ss]+=Integer.parseInt(b1[ss])/a.length;
}
}
pr(ret1);
pr(ret2);
}
public static void pr(int a[]){
String s$="";
for(int i=0;i<a.length;i++){
s$+=a[i]+" ";
}
System.out.println(s$);
}
}
public class aa{
public static void main(String args[]){
String a[]={"100,100","90,90","80,80"};
String b[]={"90,90,90","60,60,60"};
nn.n1(a);
nn.n1(b);
}
}
[ 本帖最后由 虾B写 于 2010-2-22 07:38 编辑 ]
----------------解决方案--------------------------------------------------------
数据加载中...
[ 本帖最后由 虾B写 于 2010-2-22 07:48 编辑 ]
----------------解决方案--------------------------------------------------------
楼上果然是新手……oj的数据不仅仅是给的几个……
J2SE没有大虾么
----------------解决方案--------------------------------------------------------
程序代码:
import java.math.*;
import java.util.*;
class nn{
public static void n1(String a[]){
int s1=a[0].split(",").length;
int ret1[]=new int[a.length];
int ret2[]=new int[s1];
for(int s=0;s<a.length;s++){
String b1[]= a[s].split(",");
for(int ss=0;ss<s1;ss++){
ret1[s]+=Integer.parseInt(b1[ss]);
ret2[ss]+=Integer.parseInt(b1[ss])/a.length;
}
}
pr(ret1,"个人总分");
pr(ret2,"科目平均分");
}
public static void pr(int a[],String f){
String s$="";
for(int i=0;i<a.length;i++){
s$+=a[i]+" ";
}
System.out.println(f + s$);
}
}
public class aa{
public static void main(String args[]){
Scanner scan = new Scanner(System.in);
System.out.println("请输入人数");
String ar[]=new String[scan.nextInt()];
System.out.println("请输入各科成绩,用\",\"号用割");
for(int i=0;i<ar.length;i++){
ar[i]= scan.next();
}
nn.n1(ar);
}
}
import java.util.*;
class nn{
public static void n1(String a[]){
int s1=a[0].split(",").length;
int ret1[]=new int[a.length];
int ret2[]=new int[s1];
for(int s=0;s<a.length;s++){
String b1[]= a[s].split(",");
for(int ss=0;ss<s1;ss++){
ret1[s]+=Integer.parseInt(b1[ss]);
ret2[ss]+=Integer.parseInt(b1[ss])/a.length;
}
}
pr(ret1,"个人总分");
pr(ret2,"科目平均分");
}
public static void pr(int a[],String f){
String s$="";
for(int i=0;i<a.length;i++){
s$+=a[i]+" ";
}
System.out.println(f + s$);
}
}
public class aa{
public static void main(String args[]){
Scanner scan = new Scanner(System.in);
System.out.println("请输入人数");
String ar[]=new String[scan.nextInt()];
System.out.println("请输入各科成绩,用\",\"号用割");
for(int i=0;i<ar.length;i++){
ar[i]= scan.next();
}
nn.n1(ar);
}
}
我只是想把大概写出来,细节就不写了 如:数字的安全检测 或者 数字通过double除过后相加再转换成int确保精度 又或者成绩一个一个输入后用函数转换成需要的格式
----------------解决方案--------------------------------------------------------
建议你去读读OJ的FAQ
另外,问题我找到了,谢谢你啊
----------------解决方案--------------------------------------------------------