Link:

P1580 传送门

Solution:

拿来练练字符串的读入:

1、$gets()$相当于$c++$中的$getline()$,但返回值为指针!(无数据时为NULL)

(都读入换行符,并将其舍弃)

2、$sscanf(起始指针,.....,......)$可以实现从另一个字符串读入

3、$strcmp$和$memcmp$都是相同时返回值为0

4、$count(begin,end,value)$能实现各个容器中的个数查找

5、$strstr(s1,s2)$能查找$s1$中第一个$s2$的位置,没有子串$s2$时返回$NULL$!

Tips:

1、字符串中的查找函数未找到时返回的是$NULL$

对$NULL$调用会RE,使用前一定要判断

2、这道题数据出的不太好,结束符是一个空格……(不是回车或EOF)

Code:

#include <bits/stdc++.h>

using namespace std;
const int MAXN=;
int cur=;
char text[MAXN],fst[MAXN],n1[MAXN],n2[MAXN]; int main()
{
gets(text);
sscanf(strstr(text,"@"),"@yyy loves %s",fst);
while(++cur)
{
gets(text);
if(strlen(text)==) break; sscanf(text,"yyy loves %s",n1);
if(!strcmp(n1,fst))
return printf("Successful @yyy loves %s attempt",fst),;
//调用指针前要判断
if(strstr(text,"@")!=NULL) sscanf(strstr(text,"@"),"@yyy loves %s",n2);
if(count(text,text+strlen(text),'@')!= || strcmp(n2,fst))
{//注意对count函数的使用
printf("Unsuccessful @yyy loves %s attempt\n",fst);
printf("%d\nyyy loves %s",cur,n1);return ;
}
}
printf("Unsuccessful @yyy loves %s attempt\n",fst);
printf("%d\nGood Queue Shape",cur-);
return ;
}

[P1580] yyy loves Easter_Egg I的更多相关文章

  1. 洛谷 P1580 yyy loves Easter_Egg I

    洛谷 P1580 yyy loves Easter_Egg I 题解: 队列+字符串 #include <cstdio> #include <string> #include ...

  2. [洛谷P1580]yyy loves Easter_Egg I

    题目大意:很多人@一个人,如果那个人忍不住说话了,就轰炸成功,如果那个人没说话或者别的人没有@他或@很多个人,则轰炸失败.(具体见原题) 解题思路:字符串处理,好好用sscanf即可(细节见代码). ...

  3. 题解 洛谷 P1580 【yyy loves Easter_Egg I】

    一言不合上代码: #include<cstdio> #include<cstring> ],bz[],dmz[]; int maohao,xf,ls,sss,lll,xxf,x ...

  4. [洛谷1580]yyy loves Easter_Egg I

    题目背景 Soha的出题效率着实让人大吃一惊.OI,数学,化学的题目都出好了,物理的题还没有一道.于是,Huntfire,absi2011,lanlan对soha进行轮番炸,准备炸到soha出来,不料 ...

  5. yyy loves Easter_Egg I(恶心的字符串模拟)

    题目背景 Soha的出题效率着实让人大吃一惊.OI,数学,化学的题目都出好了,物理的题还没有一道.于是,Huntfire,absi2011,redbag对soha进行轮番炸,准备炸到soha出来,不料 ...

  6. 【洛谷1580】yyy loves Easter_Egg I(字符串处理题)

    点此看题面 大致题意: 略.(一道模拟题,自己去看题面吧) 几个字符数组函数 纯粹是一道字符串处理题,就当是学了一下各种与字符数组相关的函数吧! \(gets()\):这个是比较常用的函数,就是读入一 ...

  7. 洛谷P2397 yyy loves Maths VI (mode)

    P2397 yyy loves Maths VI (mode) 题目背景 自动上次redbag用加法好好的刁难过了yyy同学以后,yyy十分愤怒.他还击给了redbag一题,但是这题他惊讶的发现自己居 ...

  8. P2393 yyy loves Maths II

    P2393 yyy loves Maths IIlong double比如保留5位小数*1000000都变成整数最后再/1000000避免精度误差scanf("%Lf",& ...

  9. 洛谷P2396 yyy loves Maths VII

    P2396 yyy loves Maths VII 题目背景 yyy对某些数字有着情有独钟的喜爱,他叫他们为幸运数字;然而他作死太多,所以把自己讨厌的数字成为"厄运数字" 题目描述 ...

随机推荐

  1. chrome 不支持12px以下字体为题的解决

    现英文9px 设置 在chrome 下无效,可以通过 -webkit-transform: scale(0.75); 12*0.75 =9  得到小字体(在chrome浏览器下 大小缩放到0.75倍) ...

  2. cloudera manager配置

    cloudera manager的数据库配置文件位置:    /etc/cloudera-scm-server/db.properties

  3. 异常message:There is no database named cloudera_manager_metastore_canary_test_db_hive_hivemetastore

    NoSuchObjectException(message:There is no database named cloudera_manager_metastore_canary_test_db_h ...

  4. JavaBean定义、JSP中使用以及内省操作

        Apache commons 一系列的开源工具室非常值得学习的实现. 一 JavaBean定义     JavaBean是一种可重复使用.且跨平台的软件组件.JavaBean可分为两种:一种是 ...

  5. nginx实时生成缩略图到硬盘上

    现在随着各终端的出现(手机,ipad等平板),以及各种终端的手机分辨率和尺寸都不同,现在手机用户流量都是宝,网上出现了各种各样的生成缩略图功能的架构,有使用php实时生成缩略图的,也有用nginx + ...

  6. 有关javamelody的配置

    一:前沿 在这里我学到了怎么来使用开源的东西,也第一次去接触有关性能方面检测的开源框架,javamelody是性能检测的,刚刚看的时候我什么都不知道的,但是自己接触了,才知道一点大概思路吧.下面来记载 ...

  7. Notepad++64插件安装方法

    首先通过https://github.com/bruderstein/nppPluginManager/releases下载"nppPluginManager",下载解压后放到对应 ...

  8. rest service技术选型

    MySql workbench下载 http://dev.mysql.com/downloads/workbench/ 最好的8个 Java RESTful 框架 http://colobu.com/ ...

  9. bzoj 1601 最小生成树

    原题传送门http://www.lydsy.com/JudgeOnline/problem.php?id=1601 最小生成树的比较水的题,我们只需要加一个源点,连向所有的点,边权为每个点建水库的代价 ...

  10. [Leetcode Week6]Linked List Cycle II

    Linked List Cycle II 题解 题目来源:https://leetcode.com/problems/linked-list-cycle-ii/description/ Descrip ...