飞行的猪哼哼

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

做乘法
Time Limit: 1000 ms Memory Limit: 65536 KiB
Submit Statistic
Problem Description

请用C语言编写一个程序。此程序接收一个正整数N,然后打印输出“N次N*(1->N)格式”的数据。例如:此程序接收正整数5,那会输出以下格式的数据:
5*1=5
5*2=10
5*3=15
5*4=20
5*5=25

Input

只有一个正整数N(N<=100)。
Output

输出共N行数据,如上面的例子所示。
Sample Input

5
Sample Output

5*1=5
5*2=10
5*3=15
5*4=20
5*5=25

import java.util.Scanner;
public class Main
{
    public static void main(String[] args) 
    {
         Scanner reader = new Scanner(System.in);
          int N = reader.nextInt();
          for(int i=1;i<=N;i++)
          {
              int M=N*i;
              System.out.printf("%d*%d=%d\n",N,i,M);
          }

    }
}

C语言实验——for循环打印图形(循环结构)
Time Limit: 1000 ms Memory Limit: 65536 KiB
Submit Statistic
Problem Description

通过使用双重for循环语句,打印下列图形:
提交
Input

Output

Sample Input

Sample Output

*






*

import java.util.Scanner;
public class Main
{
    public static void main(String[] args) 
    {
         Scanner reader = new Scanner(System.in);
        for(int i=1;i<=4;i++)
        {
            for(int j=4-i;j>=1;j--)
            {
                System.out.print(" ");
            }
            for(int j=1;j<=2*i-1;j++)
            {
                System.out.print("*");
            }
            System.out.printf("\n");
        }
        for(int i=3;i>=1;i--)
        {
            for(int j=i;j<=3;j++)
            {
                System.out.print(" ");
            }
            for(int j=2*i-1;j>=1;j--)
            {
                System.out.print("*");
            }
            System.out.print("\n");
        }

    }
}

期末考试之分等级
Time Limit: 1000 ms Memory Limit: 65536 KiB
Submit Statistic
Problem Description

期末考试结束了,老师想要根据学生们的成绩划分出等级。共有5个等级A,B,C,D和E。
划分方法如下,90分(含90)以上的为A,80~90(含80)间的为B,70~80(含70)间的为C,
60~70(含60)的为D,不及格的为E。
根据输入的成绩,编程输出各个级别段人数。

Input

输入第一行包含一个正整数N(N<= 100)代表学生的数目,接下来有N行数据每行一个整数(0~100)代表
一个学生的成绩。
Output

输出有五行格式如下:
A nA
B nB
C nC
D nD
E nE
其中A,B,C,D,E代表等级,nA,nB等代表个等级的人数,等级和人数之间有一个空格。
Sample Input

6
66
73
85
99
100
59
Sample Output

A 2
B 1
C 1
D 1
E 1

import java.util.Scanner;
public class Main
{
    public static void main(String[] args) 
    {
         Scanner reader = new Scanner(System.in);
         int N=reader.nextInt();
         int a=0,b=0,c=0,d=0,e=0;
         for(int i=1;i<=N;i++)
         {
             int X=reader.nextInt();
             if(X>=90)a++;
             else if(X>=80)b++;
             else if(X>=70)c++;
             else if(X>=60)d++;
             else e++;
         }
         System.out.printf("A %d\nB %d\nC %d\nD %d\nE %d\n",a,b,c,d,e);
    }
}

C语言实验——矩阵转置
Time Limit: 1000 ms Memory Limit: 65536 KiB
Submit Statistic
Problem Description

输入N*N的矩阵,输出它的转置矩阵。
Input

第一行为整数N(1≤N≤100)。
接着是一个N*N的矩阵。
Output

转置矩阵。
Sample Input

2
1 2
1 2
Sample Output

1 1
2 2

import java.util.Scanner;
public class Main
{
    public static void main(String[] args) 
    {
         Scanner reader = new Scanner(System.in);
         int A[][];
         A=new int[100][100];
         int n=reader.nextInt();
         for(int i=0;i<=n-1;i++)
         {
            for(int j=0;j<=n-1;j++)
            {
                A[i][j]=reader.nextInt();
            }
         }
         for(int i=0;i<=n-1;i++)
         {
            for(int j=0;j<=n-1;j++)
            {
                if(j!=n-1)
                    System.out.printf("%d ",A[j][i]);
                else
                    System.out.printf("%d\n",A[j][i]);
            }
         }

    }
}

C语言实验——矩阵下三角元素之和
Time Limit: 1000 ms Memory Limit: 65536 KiB
Submit Statistic
Problem Description

输入一个正整数n(1<=n<=10),再输入n*n的矩阵,要求求该矩阵的下三角元素之和。
Input

输入包括n+1行。
第一行为整数n;
接下来的n行为矩阵数据。
Output

矩阵的下三角元素之和。
Sample Input

5
1 2 3 4 5
2 3 4 5 6
3 4 5 6 7
4 5 6 7 8
5 6 7 8 9
Sample Output

75

import java.util.Scanner;

import com.sun.jndi.url.iiopname.iiopnameURLContextFactory;
public class Main
{
    public static void main(String[] args) 
    {
         Scanner reader = new Scanner(System.in);
         int A[][];
         A=new int[11][11];
         int n=reader.nextInt();
         for(int i=0;i<=n-1;i++)
         {
            for(int j=0;j<=n-1;j++)
            {
                A[i][j]=reader.nextInt();
            }
         }
         int sum=0;
         for(int i=0;i<=n-1;i++)
         {
             for(int j=0;j<=i;j++)
             {
                 sum=sum+A[i][j];
             }
         }
         System.out.println(sum);
    }
}

排序
Time Limit: 1000 ms Memory Limit: 32678 KiB
Submit Statistic
Problem Description

给你N(N<=100)个数,请你按照从小到大的顺序输出。

Input

输入数据第一行是一个正整数N,第二行有N个整数。

Output

输出一行,从小到大输出这N个数,中间用空格隔开。

Sample Input

5
1 4 3 2 5
Sample Output

1 2 3 4 5

import java.util.Scanner;

import com.sun.jndi.url.iiopname.iiopnameURLContextFactory;
public class Main
{
    public static void main(String[] args) 
    {
         Scanner reader = new Scanner(System.in);
         int A[];
         A=new int [101];
         int N=reader.nextInt();
         for(int i=0;i<=N-1;i++)
         {
            A[i]=reader.nextInt(); 
         }
         int t;
         for(int i=0;i<=N-2;i++)
         {
             for(int j=0;j<=N-2-i;j++)
             {
                 if(A[j]>A[j+1])
                 {
                     t=A[j];A[j]=A[j+1];A[j+1]=t;
                 }
             }
         }
         for(int i=0;i<=N-1;i++)
         {
             if(i!=N-1)
            System.out.printf("%d ",A[i]);
             else
            System.out.printf("%d\n",A[i]);  
         }
    }
}

期末考试之排名次
Time Limit: 1000 ms Memory Limit: 65536 KiB
Submit Statistic
Problem Description

期末考试结束了,童鞋们的成绩也出来的了,可是为了排名次可忙坏了老师,因为学生太多了。这时,老师把这个任务交给了你,希望你能帮老师完成。作为IT人,你当然不能用笨笨的人工方法了,编程解决才是好办法。
共有三门课,语文、数学和英语,要求根据学生的各科成绩计算出其总成绩,并根据总成绩从高到低排序。
Input

第一行一个整数N(N<=100),代表学生的人数。
接下来的N行数据,每行有三个整数,C,M,E分别代表一个学生语文、数学和英语的成绩。
Output

一共N行,每行一个数,从大到小,分别代表各个学生的总成绩。
Sample Input

3
70 80 90
59 59 59
100 100 100
Sample Output

300
240
177

import java.util.Scanner;

import com.sun.jndi.url.iiopname.iiopnameURLContextFactory;
public class Main
{
    public static void main(String[] args) 
    {
         Scanner reader = new Scanner(System.in);
         int A[];
         A=new int [101];
         int N=reader.nextInt();
         for(int i=0;i<=N-1;i++)
         {
            int a=reader.nextInt(); 
            int b=reader.nextInt(); 
            int c=reader.nextInt(); 
            A[i]=a+b+c;
         }
         int t;
         for(int i=0;i<=N-2;i++)
         {
             for(int j=0;j<=N-2-i;j++)
             {
                 if(A[j]<A[j+1])
                 {
                     t=A[j];A[j]=A[j+1];A[j+1]=t;
                 }
             }
         }
         for(int i=0;i<=N-1;i++)
         {
            System.out.printf("%d\n",A[i]);  
         }
    }
}
posted on 2018-09-16 19:46  飞行的猪哼哼  阅读(30)  评论(0)    收藏  举报