每日一水之strcmp用法
若str1>str2,则返回正数。
P1001 谁拿了最多奖学金
NOIP2005 第一题
记录信息
| 评测状态 | Accepted |
| 题目 | P1001 谁拿了最多奖学金 |
| 递交时间 | 2017-01-24 09:47:38 |
| 代码语言 | C++ |
| 评测机 | ShadowShore |
| 消耗时间 | 0 ms |
| 消耗内存 | 732 KiB |
| 评测时间 | 2017-01-24 09:47:40 |
评测结果
编译成功
foo.cpp: In function 'int main()':
foo.cpp:13:45: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[21]' [-Wformat=]
scanf("%s%d%d",&name,&ave1,&ave2);
^
foo.cpp:15:36: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[2]' [-Wformat=]
scanf("%s%s%d",&c,&d,&e);
^
foo.cpp:15:36: warning: format '%s' expects argument of type 'char*', but argument 3 has type 'char (*)[2]' [-Wformat=]
测试数据 #0: Accepted, time = 0 ms, mem = 732 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 732 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 728 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 728 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 728 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 728 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 728 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 728 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 728 KiB, score = 10
测试数据 #9: Accepted, time = 0 ms, mem = 728 KiB, score = 10
Accepted, time = 0 ms, mem = 732 KiB, score = 100
/*此题我也是有点纳闷,后来看别人的题解,要用到strcmp函数会过,或者直接暴力枚举就会过*/
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,ave1,ave2,e,ch[];
char name[],maxname[],c[],d[];
memset(ch,,sizeof(ch)); //数组要清零
while(scanf("%d",&n)!=EOF)
{
int max=,count=;
for(int i=;i<n;i++)
{
scanf("%s%d%d",&name,&ave1,&ave2);
getchar();
scanf("%s%s%d",&c,&d,&e);
if(ave1>&&e>=)ch[i]+=;
if(ave1>&&ave2>)ch[i]+=;
if(ave1>)ch[i]+=;
if(ave1>&&strcmp(d,"Y")==)ch[i]+=;//比较的是ASCII码表上的值,其实是若两个字符不相同,那就返回0,说明命题为真!
if(ave2>&&strcmp(c,"Y")==)ch[i]+=;//这里也是一个意思
count+=ch[i];
if(ch[i]>max)
{
max=ch[i];
strcpy(maxname,name);
}
}
printf("%s\n%d\n%d\n",maxname,max,count);
}
return ;
}
每日一水之strcmp用法的更多相关文章
- strcmp用法
strcmp() 用来比较字符串(区分大小写),其原型为: int strcmp(const char *s1, const char *s2); [参数]s1, s2 为需要比较的两个字符串. ...
- 指针数组学习中的小插曲真是醉了-----Strcmp用法
参考: 1.C++ 从入门到精通第三版: 2.https://blog.csdn.net/liaoshengshi/article/details/45099923 如是多次被别人转载的地址 ...
- [置顶] [MATLAB技术贴]漫谈MATLAB矩阵转置
矩阵转置是matlab最基本的操作了,但这个基本操作,也是很多初学者容易出现问题的地方.本帖通过几个实例演示matlab矩阵转置的操作. 方法一:' 运算符与 .' 运算符 >>a ...
- C语言和C++中的字符串(string)
知识内容: 1.C\C++字符串简述 2.C字符串相关操作 3.C++ string类相关操作 一.C\C++字符串简述 1.C语言字符串 C语言字符串是字符的数组.单字节字符串顺序存放各个字符串,并 ...
- c++判断两字符串是否相等
正确写法: 头文件: #include<string.h> if(strcmp(str.c_str(),str1.c_str())==0) 注意:以下写法在提交到 vj 全是错 if(st ...
- 关于strcmp函数的用法
strcmp函数是在string.h库下的han函数, 具体用法如下: strcmp函数是用来比较2个字符串的函数,如srcmp(字如果符串1,字符串2),从第一个字符开始比较,如果到最后两个字符串完 ...
- strcmp函数和memcmp函数的用法区别及联系
前言: C语言中有很多东西容易搞混,最近笔者就遇到了一个问题.这里做个记录.就是memcmp和strcmp两者的用法,这里做个对比: 功能对比: A memcmp: 函数原型: int memcmp( ...
- strcmp()字符串比较函数用法
函数原型: int strcmp(const char *s1, const char *s2); 头文件: #include <string.h> 功能: 用来比较两个字符串 参数: s ...
- 一个脚本和一个容易疏忽的问题strcmp、strncmp、memcmp的用法【原创】
一个容易疏忽的问题: strcmp.strncmp.memcmp, 对于memcmp进行字符串比较时可能会出现内存重叠的情况 status = strncmp(xdev->product, &q ...
随机推荐
- package。。
如果在源代码内没有加上 package ... 是无法以下面的方式访问到主类的. D:\lab_>java timer.LambdaTest 加载时会返回 "错误: 找不到或无法加载主 ...
- nginx 防 webshell 跨目录
对于在一台服务器上有多个虚拟主机的人来说,Apache有一个很好用的地方---配置php_admin_value,在里面配置一下 open_basedir就可以了. 但是Nginx却没有这样的设置 ...
- (简单) POJ 2406 Power Strings,扩展KMP。
Description Given two strings a and b we define a*b to be their concatenation. For example, if a = & ...
- [iOS Animation]CALayer-图层时间
图层时间 时间和空间最大的区别在于,时间不能被复用 -- 弗斯特梅里克 在上面两章中,我们探讨了可以用CAAnimation和它的子类实现的多种图层动画.动画的发生是需要持续一段时间的,所以计时对整个 ...
- MapReduce 简单的全文搜索
上一个已经实现了反向索引,那么为什么不尝试下全文搜索呢.例如有了 Hello file3.txt:1; MapReduce file3.txt:2;fil1.txt:1;fil2.tx ...
- C++中string中的erase函数怎么使用
erase函数的原型如下:(1)string& erase ( size_t pos = 0, size_t n = npos );(2)iterator erase ( iterator p ...
- Java-设计模式-单例模式-饿汉模式、懒汉模式
//-------------------------------------------------------------饿汉模式--开始----------------------------- ...
- CentOS标准目录结构
原博:http://www.centoscn.com/CentOS/2014/0424/2861.html/ 最高层root --- 启动Linux时使用的一些核心文件.如操作系统内核.引导程序Gru ...
- linux系统安装iprouter
在上文中将mpls编译进了linux内核,现在需要安装iprouter,安装过程如下: 1) 下载两个文件iproute2-2.6.39.tar.gz和iproute2-v2.6.39-mpls.pa ...
- idea 15破解方法记录
So easy! Only one step. 注册时选择 License server ,填 http://idea.lanyus.com 对于Clion等同样适用.