【牛客网】oj输入输出练习


a+b,多组

import java.util.*;
public class Main {
  public static void main(String[] args){
      Scanner scanner = new Scanner(System.in);
      ArrayList<Integer> arrays =new ArrayList<Integer>();
      while(scanner.hasNextLine()){
          String[] lines = scanner.nextLine().split(" ");
          int a =Integer.parseInt(lines[0]);
          int b = Integer.parseInt(lines[1]);
          System.out.println(a+b);
          arrays.add(a+b);
      }
      for( Integer i:arrays){
          System.out.println(i);
      }
  }       
}

字符串多行排序输出

import java.util.*;
public class Main {
  public static void main(String[] args){
      Scanner scanner = new Scanner(System.in);
      while(scanner.hasNextLine()){
          String[] lines = scanner.nextLine().split(" ");
          Arrays.sort(lines);
          for (int i = 0; i < lines.length-1; i++){
                String res = lines[i] + " ";
                System.out.print(res);
            }
          System.out.println(lines[lines.length-1]);
      }

  }       
}

字符串排序

import java.util.*;
public class Main {
  public static void main(String[] args){
      Scanner scanner = new Scanner(System.in);
      int count = Integer.parseInt(scanner.nextLine());
      String[] lines = scanner.nextLine().split(" ");
      Arrays.sort(lines);
      for (int i = 0; i < count-1; i++){
            String res = lines[i] + " ";
            System.out.print(res);
      }
      System.out.print(lines[count-1]);
  }       
}

a+b,增加换行

import java.util.*;
public class Main {
  public static void main(String[] args){
      Scanner scanner = new Scanner(System.in);
      ArrayList<Integer> arrays =new ArrayList<Integer>();
      while(scanner.hasNextLine()){
          String[] lines = scanner.nextLine().split(" ");
          if(lines.length == 2){
              int a =Integer.parseInt(lines[0]);
              int b = Integer.parseInt(lines[1]);
              arrays.add(a+b);
          }
      }
      for( Integer i:arrays){
          System.out.println(i);
      }
  }       
}

a+b,输入0结束

import java.util.*;
public class Main {
  public static void main(String[] args){
      Scanner scanner = new Scanner(System.in);
      ArrayList<Integer> arrays =new ArrayList<Integer>();
      while(scanner.hasNextLine()){
          String[] lines = scanner.nextLine().split(" ");
          int a =Integer.parseInt(lines[0]);
          int b = Integer.parseInt(lines[1]);
          if((a == 0)|| (b == 0)){
              break;
          }
          arrays.add(a+b);
      }
      for( Integer i:arrays){
          System.out.println(i);
      }
  }       
}

a+b,每组数字输出求和

import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sca=new Scanner(System.in);
        ArrayList<Integer> list =new ArrayList();
        while(sca.hasNextLine()){
            String[] temp = sca.nextLine().split(" ");
            if (temp[0].equals("0"))
                break;
            int a =0;
            for(int i =1;i<temp.length;i++){
                a += Integer.parseInt(temp[i]);
            }
            list.add(a);
        }
        for(Integer i:list){
            System.out.println(i);
        }
    }
}

a+b,每组数字输出求和,且取值范围很大,会数组越界

import java.util.*;
public class Main {
  public static void main(String[] args){
      Scanner scanner = new Scanner(System.in);
      while(scanner.hasNextLine()){
          String[] lines = scanner.nextLine().split(" ");
          Long a =Long.parseLong(lines[0]);
          Long b = Long.parseLong(lines[1]);
          System.out.println(a+b);
      }
  }       
}

oj输入输出练习部分的记录就先到这!接下来,是一些整理的c++要点概要!

额外的补充

fork()系统调用的特性

fork()系统调用是 Unix 下以自身进程创建子进程的系统调用, 一次调用, 两次返回, 如果返
回是 0, 则是子进程, 如果返回值>0, 则是父进程(返回值是子进程的 pid) 。 还有一个很
重要的东西是, 在 fork()的调用处, 整个父进程空间会原模原样地复制到子进程中, 包括指
令, 变量值, 程序调用栈, 环境变量, 缓冲区, 等等。

指针与const

  • const A * 等价 A const * 。
  • 允许用 A * 赋值 A const * 。
  • 允许用 A* * 赋值 A const* const * 。
  • 不允许用 A* * 赋值 A const* * 。

友元关系

友元关系是单向的, 不是对称, 不能传递。

  • 关于传递性, 有人比喻: 父亲的朋友不一定是儿子的朋友。
  • 那关于对称性, 是不是: 他把她当朋友, 她却不把他当朋友? 如, 类 A 是类B 的友元, 类 C 是类 A 的公有派生类。 则类 C 不是类 B 的友元, 类 B 不是类 A 的友元

复杂度

  • vector 插入 ,该位置插入后后面的都要改变 O(n)
  • Set 底层红黑树 O(logn)
  • Hash_map 底层哈希表 O(1)
  • Deque 尾部可以直接修改 O(1)

抽象类的规定

  1. 抽象类只能用作其他类的基类, 不能建立抽象类对象。
  2. 抽象类不能用作参数类型、 函数返回类型或显式转换的类型。
  3. 可以定义指向抽象类的指针和引用, 此指针可以指向它的派生类, 进而实现多态性。

常成员函数

const void print(const int num)const
  • 第一个 const 修饰返回类型
  • 第二个 const 修饰参数
  • 第三个 const 修饰类的成员函数

常成员函数声明: 形如 void funcName(参数表) const;
对于常成员函数需要注意:

  1. 其实现部分也要带 const 关键字;
  2. 不能修改类的成员变量, 不能调用类中没有被 const 修饰的成员函数(即只能调用常成员函数) 。

易错点

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

傻傻虎虎

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值