长春网站制作推广,石家庄房和城乡建设部网站,网站的二次开发是什么意思,C 网站开发招聘前言从去年10月份开始就一直都在九度oj平台写acm#xff0c;到今天在九度oj的总排名已经到了第6名#xff0c;收获很多特别是算法和数据结构方面的提高#xff0c;这种提高直接反映在我找工作的顺利中但是人总要学会拥抱变化#xff0c;特别是我即将加入阿里系#xff0c;…前言从去年10月份开始就一直都在九度oj平台写acm到今天在九度oj的总排名已经到了第6名收获很多特别是算法和数据结构方面的提高这种提高直接反映在我找工作的顺利中但是人总要学会拥抱变化特别是我即将加入阿里系使用java编程不能继续贪恋用c的快感尽快调节自己。因此从今天开始我要转换自己的acm平台开始使用LeetCode OJ有点跑题毕竟这篇博客还是偏向技术一些不搞心灵鸡汤类似的东西因此这里主要讲一下在写ACM时如何快速的从c到java实现转变基本输入输出其实我感觉在有c基础后学习java还是挺简单的写acm时候主要是不太适应java的输入输出其实关键还是在于你心里是否接受java的语法(吐槽java的api的名字太TM长了吧)在c里输入输出的标准格式#include int main(void){int a, b;while (scanf(%d %d, a, b) ! EOF) {printf(%d\n, a b);}return 0;}在java里提供了Scanner类可以方便我们跟c一样进行输入输出import java.util.*;public class IOclass {public static void main(String[] args) {Scanner cin new Scanner(System.in);int a, b;while (cin.hasNext()) {a cin.nextInt();b cin.nextInt();System.out.printf(%d\n, a b);}}}API对比(java vs c)读一个整数 int a cin.nextInt(); 相当于 scanf(%d, a);读一个字符串 String s cin.next(); 相当于 scanf(%s, s);读一个浮点数 double t cin.nextDouble(); 相当于 scanf(%lf, t);读取整行数据 String s cin.nextLine() 相当于 gets(s);判断是否有下一个输出 while (cin.hasNext) 相当于 while (scanf(%d, n) ! EOF)输出 System.out.printf(); 相当于 printf();方法调用在java主类中main方法必须是public static void的在main中调用非static方法时会报出错误因此需要先建立对象然后调用对象的方法题目Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?代码import java.util.*;public class SingleNumber {public static void main(String[] args) {int n, key, A[] new int[1000];Scanner cin new Scanner(System.in);while (cin.hasNext()) {// 接收数组An cin.nextInt();for (int i 0; i n; i ) {A[i] cin.nextInt();}// 调用方法SingleNumber sn new SingleNumber();key sn.singleNumber(A, n);System.out.println(key);}}public int singleNumber(int[] A, int n) {// IMPORTANT: Please reset any member data you declared, as// the same Solution instance will be reused for each test case.for (int i 1; i A.length; i) {A[0] ^ A[i];}return A[0];}}