Love丶FFC's Blog
本题要求读入 N 名学生的成绩,将获得某一给定分数的学生人数输出。
输入在第 1 行给出不超过 105 的正整数 N,即学生总人数。随后一行给出 N 名学生的百分制整数成绩,中间以空格分隔。最后一行给出要查询的分数个数 K(不超过 N 的正整数),随后是 K 个分数,中间以空格分隔。
在一行中按查询顺序给出得分等于指定分数的学生人数,中间以空格分隔,但行末不得有多余空格。
10
60 75 90 55 75 99 82 90 75 50
3 75 90 88
3 2 0
1.Python直接使用count方法进行查询
但使用Python会导致最后一个测试点超时
一开始认为超时是因为Python性能的缘故,因此尝试了Java、C语言使用双层循环计数的方法,但是仍然超时
1.突然想到一个办法,何不直接创建一个100长度的数组,每输入一个成绩就将对应下标的元素值+1
这样就省去了查询的时间,直接输出查询的成绩对应下标的数组元素即可,使用这个方法大大提高了效率!
NOS = int(input()) # 输入成绩个数,Number Of Students Score = list(map(int, input().split())) # 存放学生成绩 Query = list(map(int, input().split())) # 存放查询次数、具体查询的成绩 NOQ = Query[0] # 将查询次数单独存放,便于后续操作,Number Of Queries Query.pop(0) # 将查询次数从列表从删除,只保留具体查询的成绩,便于后续操作 for i in range(NOQ - 1): # 为了保证输出没有多余的空格,只查询n-1个成绩 print(Score.count(Query[i]), end=' ') print(Score.count(Query[len(Query) - 1])) # 查询第n个成绩
#include<stdio.h> int main(void){ int Frequency[100];//创建一个数组,存放0-100分每个成绩的个数 for(int i=0;i<100;i++) { Frequency[i]=0;//数组初始化,将每个成绩的个数默认为0 } int NOS;//成绩个数 scanf("%d",&NOS); int Score; for(int i=0;i<NOS;i++) { scanf("%d",&Score);//输入成绩 Frequency[Score]++;//将成绩对应下标的数组元素+1,例如76分,则Frequency[76]++ } int NOQ;//查询成绩的个数 scanf("%d",&NOQ); int Query[NOQ]; for(int i=0;i<NOQ;i++) { scanf("%d",&Query[i]);//输入查询的成绩 } for(int i=0;i<NOQ-1;i++)//输出前n-1个成绩对应的次数 { printf("%d ",Frequency[Query[i]]); } printf("%d",Frequency[Query[NOQ-1]]);//输出第n个成绩对应的次数 }
cheap louis vuitton online
I just wanted to thank you for the fast service. alternatively they look great. I received them a day earlier than expected. for example the I will definitely continue to buy from this site. regardless I will recommend this site to my friends. Thanks!
cheap louis vuitton online https://www.cheapreallouisvuitton.com/
cheap jordan shoes
I just wanted to thank you for the fast service. as well as they look great. I received them a day earlier than expected. cherish the I will definitely continue to buy from this site. anyway I will recommend this site to my friends. Thanks!
cheap jordan shoes https://www.cheaprealjordan.com/
cheap jordans online
I just wanted to thank you for the fast service. alternatively they look great. I received them a day earlier than expected. including I will definitely continue to buy from this site. manner in which I will recommend this site to my friends. Thanks!
cheap jordans online https://www.realjordansretro.com/
cheap louis vuitton handbags
I just wanted to thank you for the fast service. while well as they look great. I received them a day earlier than expected. which includes the I will definitely continue to buy from this site. you decide I will recommend this site to my friends. Thanks!
cheap louis vuitton handbags https://www.louisvuittonsoutletstore.com/
cheap louis vuitton handbags
I just wanted to thank you for the fast service. or perhaps they look great. I received them a day earlier than expected. for example the I will definitely continue to buy from this site. situation I will recommend this site to my friends. Thanks!
cheap louis vuitton handbags https://www.bestlouisvuittonoutlet.com/
cheap jordans online
Read reviews and was a little hesitant since I had already inputted my order. and even but thank god, I had no issues. for example the received item in a timely matter, they are in new condition. regardless so happy I made the purchase. Will be definitely be purchasing again.
cheap jordans online https://www.cheapjordanssneakers.com/
FoorryNox
non dairy products, 25 studies cialis buy I had a bilateral There should also be more discussion about self image following breast cancer surgery
Preliaf
PMID 8769998 finasteride 5 mg generic tablets One substitution was in codon 191, ACA threonine rather than GCA alanine, and the other was in codon 283, TTT phenylalanine instead of TTG leucine
yZptQT
However, RER was significantly lower in HFD fed BIBO3304 treated mice compared to vehicle treated control mice in both, the light and the dark phases Fig cialis 40 mg Despite the persistence of significant disparities, few evaluations examine disparities in laboratory testing by race ethnicity, age, sex, Medicaid eligibility, and number of chronic conditions for Medicare fee for service beneficiaries newly prescribed medications