做了51的大佬求编程AC代码啊

第一次看到要写多线程,不知道咋输入啊







全部评论
第一题,直接输出2,ac了50%,这测试用例太玄学了
点赞 回复 分享
发布于 2017-09-18 21:03
虽然我也没写线程a了,但感觉没什么用,应该是考察多线程编程的,会去看的
点赞 回复 分享
发布于 2017-09-18 21:03
import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.concurrent.ArrayBlockingQueue;import java.util.concurrent.BlockingQueue;import java.util.concurrent.CountDownLatch;import java.util.concurrent.atomic.AtomicInteger;public class Main22 { private static AtomicInteger count = new AtomicInteger(0); private static final int THREAD_COUNT = 3; public static void main(String[] args) throws IOException, InterruptedException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line = null; // Scanner scan = new Scanner(System.in); BlockingQueue<String> bq = new ArrayBlockingQueue<>(200009); while ((line = br.readLine()) != null) { if ("".equals(line)) break; bq.put(line); } bq.add("__QUIT__"); bq.add("__QUIT__"); bq.add("__QUIT__"); CountDownLatch cdl = new CountDownLatch(THREAD_COUNT); Runnable task = new Runnable() { public void run() { while (true) { try { String str = bq.take(); if("__QUIT__".equals(str)){ cdl.countDown(); break; } if (str.contains("u51")) { count.incrementAndGet(); } } catch (InterruptedException e) { throw new RuntimeException(e); } } } }; Thread[] threads = new Thread[THREAD_COUNT]; for (int i = 0; i < THREAD_COUNT; i++) { threads[i] = new Thread(task); threads[i].start(); } cdl.await(); System.out.println(count.get()); }}
点赞 回复 分享
发布于 2017-09-18 21:28
不用写线程
点赞 回复 分享
发布于 2017-09-18 20:50
不用写线程,就是个噱头
点赞 回复 分享
发布于 2017-09-18 20:58
单线程一下a了
点赞 回复 分享
发布于 2017-09-18 21:01
没有多线程
点赞 回复 分享
发布于 2017-09-18 21:07
虽然只有3个线程 但是我还是用了线程池 = = 
点赞 回复 分享
发布于 2017-09-18 21:29
import java.util.*; public class Main{     public static void main(String args[]){         int count = 0;         Scanner sc =new Scanner (System.in);         while(sc.hasNext()){         String s = sc.nextLine();         int a = s.indexOf("u51");         if(a!=-1){count++;}        }        System.out.print(count);     } }
点赞 回复 分享
发布于 2017-09-18 21:34
我会告诉你我在网吧写不进去了,随便这样写了 结果过了(虽然没卵用,多线程肯定会看代码)
点赞 回复 分享
发布于 2017-09-18 21:34
写了多线程 本地输入测试可以通过 提交一直0 浪费了很久时间
点赞 回复 分享
发布于 2017-09-18 22:45
循环调用kmp匹配ac的
点赞 回复 分享
发布于 2017-09-19 21:55
import java.util.Scanner; import java.util.Vector; import java.util.concurrent.*; public class Main { public static void main(String[] args) throws ExecutionException, InterruptedException { Vector<String> queue=new Vector<String>(); CountDownLatch latch=new CountDownLatch(1); Produce produce = new Produce(queue,latch); ExecutorService service = Executors.newFixedThreadPool(4); service.execute(produce); Future<Integer> submit1 = service.submit(new Consumer(queue,latch)); Future<Integer> submit2 = service.submit(new Consumer(queue,latch)); Future<Integer> submit3 = service.submit(new Consumer(queue,latch)); System.out.println(submit1.get()+submit2.get()+submit3.get()); service.shutdown(); } } class Produce implements Runnable{ Vector<String> queue=null; Scanner sc=new Scanner(System.in); CountDownLatch latch; Produce(Vector<String> queue,CountDownLatch latch){ this.queue=queue; this.latch=latch; } @Override public void run() { while(sc.hasNext()){ String s = sc.nextLine(); if (s.equals("110")){break;} queue.add(s); } latch.countDown(); } } class Consumer implements Callable<Integer>{ Vector<String> queue; CountDownLatch latch; Consumer(Vector<String> queue,CountDownLatch latch){ this.queue=queue; this.latch=latch; } int count=0; @Override public Integer call() throws Exception { latch.await(); while(!queue.isEmpty()){ String s = queue.remove(0); if (s.contains("u51")){ count++; } } return count; } }
点赞 回复 分享
发布于 2017-09-19 22:02

相关推荐

hanliu:1. 排版与格式问题字体与对齐问题:标题和内容的字体大小差异不够明显,无法迅速吸引目光。某些文字看起来有些拥挤(比如校园经历中的“班委成员”部分)。2. 内容逻辑性模块顺序问题:实习经历放在较靠后的位置,实际上这部分内容对应聘来说更重要,建议提前突出。细节表述不够突出:比如教育背景部分的专业课程仅仅列出名字,没有说明自己在这些课程中表现如何或者掌握了什么技能,缺乏量化描述。多余内容:例如“班委成员”和“宣传委员”这类校园经历,叙述过于普通,缺乏和岗位相关的实质性贡献。,建议简写。3. 措辞专业性表达不够精准:例如“协助班长与团支书更好地为同学服务”显得较为笼统,没有实际成果的体现。用词重复:如“学习了焊接”“学习了光检”等重复词语较多,缺乏丰富的动词来展示个人能力(如“负责”“优化”“改进”等)。技能展示不足:虽然列出了UG和CAD证书,但没有明确提到这些技能如何在实际工作中发挥作用。4. 技能匹配度技能深度不足:虽然列出了掌握的软件和技术,但没有描述技能水平(如“熟练掌握”“精通”),也没有具体案例支持这些技能。缺乏岗位导向性:比如针对机械设计与制造方向,实习经历提到了“E6尾灯项目”,但没有详细说明自己在其中的技术贡献,可能会显得经验描述泛泛而谈。5. 自我评价问题表达空泛:如“具有良好的沟通协调能力”“责任心强”之类的描述太常见,没有让人眼前一亮的特点。缺乏成果支持:自我评价中的能力没有用具体项目、经历或成就来验证,可信度较弱。 兄弟加油
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务