Course(简单的字符串处理问题)
Course
时间限制:1000 ms | 内存限制:65535 KB
【问题描述】
There is such a policy in Sichuan University that if you are not satisfied with the score of your course, you can study this course again to get a better score. If you do this and get a higher score(than the highest score he got before), it can cover the original one. And we can say this time you update the score of this course successfully.
Here is one schoolmate's all the courses he has studied and scores he got (sorted by chronological order). So could you tell me how many time he successfully update his scores of courses?
【输入】
The first of input is an integer T which stands for the number of test cases. For each test case the first line is an integer N (1 <= N <= 100) which stands for the number of courses he has studied. Then following N lines, each line contains a string (only contains letters and the length is no more than 30,which stands for the course name) and an integer (0<=integer<=100, which stands for the score of the course),separated by a space.
Remember: the best way is getting the best score in one time.
Study one course many times is not a recommended choice!
【输出】
For each test case output the number of times he update successfully.
【样例输入】
2
6
CProgramming 70
DataStructrue 80
CProgramming 80
CProgramming 60
CProgramming 90
DataStructrue 70
2
CompilerTheory 95
Network 90
【样例输出】
2
0
一道很无脑的题,简单来说就是算出成绩突破次数。我还花了半个多小时,真是打脸啊。。。。
普通结构体写法:
#include<cstdio>
#include<cstring>
struct course
{
char name[35];
int score;
}p[105];
int main()
{
int i,j,m,n,count,num,sum;
char str[35];
scanf("%d",&n);
while(n--)
{
count=sum=0;
scanf("%d",&m);
for(i=0;i<m;i++)
{
int sign=1;
scanf("%s%d",str,&num);
for(j=0;j<count;j++)
if(!strcmp(p[j].name,str)&&num>p[j].score)
{p[j].score=num;sign=0;sum++;break;}
if(sign)
{strcpy(p[j].name,str);p[j].score=num;count++;}
}
printf("%d\n",sum);
}
return 0;
}
以此为鉴,下不为例。
Course(简单的字符串处理问题)的更多相关文章
- Redis的简单动态字符串实现
Redis 没有直接使用 C 语言传统的字符串表示(以空字符结尾的字符数组,以下简称 C 字符串), 而是自己构建了一种名为简单动态字符串(simple dynamic string,sds)的抽象类 ...
- SQL点滴3—一个简单的字符串分割函数
原文:SQL点滴3-一个简单的字符串分割函数 偶然在电脑里看到以前保存的这个函数,是将一个单独字符串切分成一组字符串,这里分隔符是英文逗号“,” 遇到其他情况只要稍加修改就好了 CREATE FUN ...
- Redis数据结构之简单动态字符串SDS
Redis的底层数据结构非常多,其中包括SDS.ZipList.SkipList.LinkedList.HashTable.Intset等.如果你对Redis的理解还只停留在get.set的水平的话, ...
- 小白的Redis学习(一)-SDS简单动态字符串
本文为读<Redis设计与实现>的记录.该书以Redis2.9讲解Redis相关内容.请注意版本差异. Redis使用C语言实现,他对C语言中的char类型数据进行封装,构建了一种简单动态 ...
- redis_简单动态字符串
在redis中,C字符串(以'\0'结尾的字符数组)只用在一些无需对字符串值进行修改的地方,比如打印日志.其他情况,redis使用SDS - SimpleDynamicString 简单动态字符串,来 ...
- redis 系列3 数据结构之简单动态字符串 SDS
一. SDS概述 Redis 没有直接使用C语言传统的字符串表示,而是自己构建了一种名为简单动态字符串(simple dynamic string, SDS)的抽象类型,并将SDS用作Redis的默 ...
- 图解Redis之数据结构篇——简单动态字符串SDS
图解Redis之数据结构篇--简单动态字符串SDS 前言 相信用过Redis的人都知道,Redis提供了一个逻辑上的对象系统构建了一个键值对数据库以供客户端用户使用.这个对象系统包括字符串对象 ...
- Redis中的简单动态字符串
Redis没有直接使用C语言传统的字符串表示(以空字符结尾的字符数组,以下简称C字符串),而是自己构建了一种名为简单动态字符串(simple dynamic string,SDS)的抽象类型,并将SD ...
- Redis---SDS(简单动态字符串)
Redis 没有直接使用 C 语言传统的字符串表示(以空字符结尾的字符数组,以下简称 C 字符串), 而是自己构建了一种名为简单动态字符串(simple dynamic string,SDS)的抽象类 ...
- Redis数据类型之SDS简单动态字符串
一,简单的动态字符串 1,Redis自己构建了一种名为简单动态字符串的抽象类型,并将SDS用作Redis的默认字符串表示, 2,在redis的数据库里面,包含字符串值的键值对在底层都是由SDS实现的 ...
随机推荐
- 字节数转换为b,kb,mb,gb的方法 通用的手机流量计算方法
//通用的手机流量计算方法 private String byteToMB(long size){ long kb = 1024; long mb = kb*1024; long gb = mb*10 ...
- 【Howie玩docker】-Centos 7 docker 启动容器iptables报No chain/target/match by that name
重启了一下服务器,以前能运行的docker网络应用都不能正常开启了. 因为用的是centos7,所以猜测有可能是iptables的问题. docker start 或者run 后总是提示类似的错误: ...
- 20.org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actua ...
- JS中String添加trim()方法
这么牛的JS竟然还要自己封装trim方法. 下面利用prototype和正则表达式的添加方式添加trim(): <script language="javascript"&g ...
- Mac 上开启一个简单的服务器
终端输入命令: python -m SimpleHTTPServer 会开启一个端口为8000的本地服务器.
- struts漏洞修补过程之S2-016
Struts漏洞修补过程之S2-016.邪恶的Struts再次现身,这一次是远程执行漏洞.官方建议立即升级到2.3.15.1.真希望这是最后一次漏洞修补.下面是升级步骤. 1.升级到struts2.3 ...
- SPOJ 3267 求区间不同数的个数
题意:给定一个数列,每次查询一个区间不同数的个数. 做法:离线+BIT维护.将查询按右端点排序.从左到右扫,如果该数之前出现过,则将之前出现过的位置相应删除:当前位置则添加1.这样做就保证每次扫描到的 ...
- 2.&与&&以及位运算符。
这是单独的一块,因为一条讲不清楚(虽然内容也不够一篇),而且我之前也没好好弄清楚,所以有必要写出来. 说位运算符也是从&与&&(|与||类似)之间的区别讲起的.事实上,对于两个 ...
- JS 人民币大写
/***** HongShijin** Me@HongShijin.com** 2014-10-15 9:13:00.00000** text/javascript***/ (function ($) ...
- jQuery为多个元素绑定相同的事件
方式一: // 假设$("#div1", "#divN")有多个对象$("#div1", "#divN").each(f ...