<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><style type="text/css"&g
#-*- coding:UTF-8 -*- #环境:python3 print("Enter the numbers between 1 and 100:") enterList=[] #记录输入的元素 while 1: a = int(input(">>>")) #将输入转换为int型 if a == 0: print ("Your input:",enterList) break #结束输入 if a<1 or a&g
/** *把1到100之间的数的偶数相加 */ class Demo{ public static void main(String[] args){ int i =1; int sum = 0; do{ if(i % 2 != 0){ sum += i; } //累加器需要在if语句外面 i++; }while(i <= 100); System.out.println(sum); } }
一种是Brute force,O(nlogn) 另一种是找规律O(n),见http://hawstein.com/posts/20.4.html 当某一位的数字小于2时,那么该位出现2的次数为:更高位数字x当前位数 当某一位的数字大于2时,那么该位出现2的次数为:(更高位数字+1)x当前位数 当某一位的数字等于2时,那么该位出现2的次数为:更高位数字x当前位数+低位数字+1 package Hard; /** * Write a method to count the number of 2s
--18.查询各科成绩最高分.最低分和平均分:--以如下形式显示:-- 课程ID,课程name,最高分,最低分,平均分,及格率,中等率,优良率,优秀率--及格为>=60,中等为:70-80,优良为:80-90,优秀为:>=90--cast(cast (sum(case when c.score>=60 then 1 else 0 end)*100/(count(1)*1.0) as float) as nvarchar)+'%'及格率'--查询成绩表中三科成绩的最高分 等等select