2019-08-12到16的一些问题

1 篇文章 0 订阅
1 篇文章 0 订阅

1、

算法的时间复杂度之间的关系为:

O(1)<O(logn)<O(n)<O(nlog n)<O(n2)<O(2n)<O(n!)<O(nn) 

空间复杂度:算法所需存储空间的度量,记作: 

      S(n)=O( f(n) )           其中 n 为问题的规模。

2、Oracle根据拼音首字母给姓名排序

ORDER BY NLSSORT(NAME, 'NLS_SORT=SCHINESE_PINYIN_M')

3、JAVA字符串前补零和后补零的快速方法

 String fileName = "130181";
        System.out.println("================  前补零方法一   =================");
        DecimalFormat g1=new DecimalFormat("0000000");
        String startZeroStr = g1.format(Integer.valueOf(fileName));
        System.out.println("前补零方法一:"+startZeroStr);

        System.out.println("================  前补零方法二   =================");
        startZeroStr = String.format("%07d",Integer.valueOf(fileName));
        System.out.println("前补零方法二:"+startZeroStr);

        System.out.println("================  后补零方法一   =================");
        DecimalFormat g2=new DecimalFormat("0.000000");
        String endZeroStr = g2.format(Integer.valueOf(fileName));
        System.out.println("后补零:"+endZeroStr);
        System.out.println("虽然后补零出现这种情况,带有小数点");
        System.out.println("比如你要长度要在7位以内,可以这么做");
        System.out.println("后补零转变后:"+endZeroStr.replace(".","").substring(0,7));
输出结果如下:

================  前补零方法一   =================
前补零方法一:0130181
================  前补零方法二   =================
前补零方法二:0130181
================  后补零方法一   =================
后补零:130181.000000
虽然后补零出现这种情况,带有小数点
比如你要长度要在7位以内,可以这么做
后补零转变后:1301810

(版权声明:本文为CSDN博主「JAVA码上飘」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/wohaqiyi/article/details/79803229)

3、Tomcat 8.5 400错误:Invalid character found in the request target. 

网上找了一堆,方法都差不多,在conf里的catalina.properties中最后添加一行:

org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true

然后chrome、火狐、360没问题了,ie还是不行

然后看了看别的,有的说再加一句
tomcat.util.http.parser.HttpParser.requestTargetAllow=|{}

这个就没测试过了,大佬跟客户说别用IE用别的浏览器就行了。。。

06-08
代码如下: ```scala import org.apache.spark.{SparkConf, SparkContext} object ECommerceAnalysis { def main(args: Array[String]): Unit = { val conf = new SparkConf().setAppName("ECommerceAnalysis").setMaster("local[*]") val sc = new SparkContext(conf) // 读取数据 val cityInfo = sc.textFile("city_info.txt") val productInfo = sc.textFile("product_info.txt") val userVisitAction = sc.textFile("user_visit_action.txt") // 1. 统计最受欢迎的品类,先排序点击-再是订单-最后是支付 val categoryCount = userVisitAction.flatMap(line => { val fields = line.split("\t") if (fields(6) != "-1") { // 点击 List((fields(6), (1, 0, 0))) } else if (fields(8) != "null") { // 订单 val orderIds = fields(8).split(",") orderIds.map(orderId => (orderId, (0, 1, 0))) } else if (fields(10) != "null") { // 支付 val paymentIds = fields(10).split(",") paymentIds.map(paymentId => (paymentId, (0, 0, 1))) } else { Nil } }).reduceByKey((x, y) => (x._1 + y._1, x._2 + y._2, x._3 + y._3)) .map{case (categoryId, (clickCount, orderCount, paymentCount)) => (clickCount, orderCount, paymentCount, categoryId) }.sortBy(x => (x._1, x._2, x._3), false) .take(10) categoryCount.foreach{case (clickCount, orderCount, paymentCount, categoryId) => println(s"Category $categoryId: ClickCount: $clickCount, OrderCount: $orderCount, PaymentCount: $paymentCount") } // 2. 统计页面跳转率 val pageJumpCount = userVisitAction.map(line => { val fields = line.split("\t") val pageId = fields(5).toInt val sessionId = fields(2) val actionTime = fields(4) val actionType = fields(6).toInt (sessionId, (pageId, actionTime, actionType)) }).groupByKey().flatMap{case (sessionId, iter) => val actions = iter.toList.sortBy(_._2) val pageJumpActions = actions.zip(actions.tail) .filter{case (action1, action2) => action1._3 == 0 && action2._3 == 1} pageJumpActions.map{case ((pageId1, time1, _), (pageId2, time2, _)) => ((pageId1, pageId2), 1) } }.reduceByKey(_ + _) val pageVisitCount = userVisitAction.map(line => { val fields = line.split("\t") val pageId = fields(5).toInt val sessionId = fields(2) (sessionId, pageId) }).distinct().groupByKey().map{case (sessionId, iter) => val pageIds = iter.toList.sortBy(x => x) val pageVisitPairs = pageIds.zip(pageIds.tail) pageVisitPairs.map(pair => (pair, 1)) }.flatMap(x => x).reduceByKey(_ + _) val pageJumpRate = pageJumpCount.join(pageVisitCount).map{case ((pageId1, pageId2), (jumpCount, visitCount)) => (pageId1, (pageId2, jumpCount.toDouble / visitCount)) }.groupByKey().map{case (pageId, iter) => val pageJumpInfo = iter.toList.sortBy(-_._2).take(10) (pageId, pageJumpInfo) } pageJumpRate.foreach{case (pageId, pageJumpInfo) => println(s"Page $pageId: ${pageJumpInfo.mkString(", ")}") } // 3. 不同区域内的热门商品Top3 val cityProductCount = userVisitAction.flatMap(line => { val fields = line.split("\t") val cityId = fields(3) val productId = fields(6) if (productId != "-1") { List(((cityId, productId), 1)) } else { Nil } }).reduceByKey(_ + _) val cityTop3Product = cityProductCount.map{case ((cityId, productId), count) => (cityId, (productId, count)) }.groupByKey().map{case (cityId, iter) => val top3Product = iter.toList.sortBy(-_._2).take(3) (cityId, top3Product) } val cityMap = cityInfo.map(line => { val fields = line.split(" ") (fields(0), fields(1)) }).collectAsMap() cityTop3Product.map{case (cityId, top3Product) => val cityName = cityMap.getOrElse(cityId, "Unknown") val top3ProductStr = top3Product.map{case (productId, count) => s"$productId:${count}" }.mkString(", ") (cityName, top3ProductStr) }.foreach{case (cityName, top3ProductStr) => println(s"$cityName: $top3ProductStr") } // 4. 自定义需求 // 按小时统计访问人数 val hourVisitCount = userVisitAction.map(line => { val fields = line.split("\t") val timestamp = fields(4) val hour = timestamp.substring(11, 13) (hour, 1) }).reduceByKey(_ + _) hourVisitCount.sortByKey().foreach{case (hour, count) => println(s"Hour $hour: $count") } sc.stop() } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值