BNU 26473 Aaah!【签到--->查找字符串】

链接:

http://www.bnuoj.com/bnuoj/problem_show.php?pid=26473

http://www.bnuoj.com/bnuoj/contest_show.php?cid=2317#problem/25675

Aaah!

Time Limit: 1000ms
Memory Limit: 65536KB
64-bit integer IO format:  %lld      Java class name:  Main
Prev  Submit  Status  Statistics  Discuss  Next
Font Size:  +   -
Type:    None Graph Theory      2-SAT     Articulation/Bridge/Biconnected Component      Cycles/Topological Sorting/Strongly Connected Component      Shortest Path          Bellman Ford         Dijkstra/Floyd Warshall      Euler Trail/Circuit      Heavy-Light Decomposition      Minimum Spanning Tree      Stable Marriage Problem      Trees      Directed Minimum Spanning Tree      Flow/Matching         Graph Matching              Bipartite Matching              Hopcroft–Karp Bipartite Matching              Weighted Bipartite Matching/Hungarian Algorithm          Flow              Max Flow/Min Cut              Min Cost Max Flow  DFS-like     Backtracking with Pruning/Branch and Bound      Basic Recursion      IDA* Search     Parsing/Grammar      Breadth First Search/Depth First Search      Advanced Search Techniques          Binary Search/Bisection          Ternary Search  Geometry      Basic Geometry     Computational Geometry      Convex Hull      Pick's Theorem Game Theory      Green Hackenbush/Colon Principle/Fusion Principle      Nim      Sprague-Grundy Number  Matrix     Gaussian Elimination      Matrix Exponentiation  Data Structures      Basic Data Structures      Binary Indexed Tree      Binary Search Tree      Hashing     Orthogonal Range Search      Range Minimum Query/Lowest Common Ancestor      Segment Tree/Interval Tree      Trie Tree      Sorting     Disjoint Set  String      Aho Corasick     Knuth-Morris-Pratt      Suffix Array/Suffix Tree  Math      Basic Math     Big Integer Arithmetic      Number Theory          Chinese Remainder Theorem          Extended Euclid          Inclusion/Exclusion          Modular Arithmetic      Combinatorics         Group Theory/Burnside's lemma          Counting      Probability/Expected Value  Others     Tricky      Hardest     Unusual      Brute Force      Implementation     Constructive Algorithms      Two Pointer      Bitmask     Beginner      Discrete Logarithm/Shank's Baby-step Giant-step Algorithm      Greedy      Divide and Conquer  Dynamic Programming                      Tag it!

 

Jon Marius shouted too much at the recent Justin Bieber concert, and now needs to go to the doctor because of his sore throat. The doctor’s instructions are to say “aaah”. Unfortunately, the doctors sometimes need Jon Marius to say “aaah” for a while, which Jon Marius has never been good at. Each doctor requires a certain level of “aah” – some require “aaaaaah”, while others can actually diagnose his throat with just a “h”. (They often diagnose wrongly, but that is beyond the scope of this problem.) Since Jon Marius does not want to go to a doctor and have his time wasted, he wants to compare how long he manages to hold the “aaah” with the doctor’s requirements. (After all, who wants to be all like “aaah” when the doctor wants you to go “aaaaaah”?)

Each day Jon Marius calls up a different doctor and asks them how long his “aaah” has to be. Find out if Jon Marius would waste his time going to the given doctor.

Input

The input consists of two lines. The first line is the “aaah” Jon Marius is able to say that day. The second line is the “aah” the doctor wants to hear. Only lowercase ’a’ and ’h’ will be used in the input, and each line will contain between and 999 ’a’s, inclusive, followed by a single ’h’.

Output

Output “go” if Jon Marius can go to that doctor, and output “no” otherwise.

Sample Input

aaah
aaaaah

Sample Output

no

Source

The 2012 Nordic Collegiate Programming Contest
Prev  Submit  Status  Statistics  Discuss  Next


题意:


第一个字符串给你 Jon 能发出的声音
第二个字符串给的是医生要求听到的声音,题目中已经说明了,医生必须听到他要听的声音才能诊断。

所以如果 Jon 如果不能发出医生要求的声音,去看医生就是浪费时间。

从而题目就变成了如果第一个字符串包含了第二个字符串,则输出 go
否则输出 no


算法:STL string 字符串查找


总结:


签到题很简单了,却不能快速看明白题意,秒杀掉,实在是弱爆了。

关于string 的find() 如果查到,则返回下标值(从 0 开始),如果查不到则返回  4294967295
刚刚去查了下这个数字
点击打开链接

4294967295就是无符号位的整形最大值,也就是有符号位整形-1,也就是s.find(" ") == -1,结果就显而易见了。

所以 string s1,s2;

如果 s1中不包含 s2

令int ans = s1.find(s2)

则 ans = -1

或者说 ans = 4294967295


code:

所以像下面这么写都可以水过。
#include<stdio.h>
#include<string>
#include<iostream>
using namespace std;

string s1,s2;
const int INF = 4294967295;

int main()
{
    while(cin>>s1>>s2)
    {
        int ans = s1.find(s2);
        if(ans != INF) printf("go\n");
        else printf("no\n");
    }
}


#include<stdio.h>
#include<string>
#include<iostream>
using namespace std;

string s1,s2;
const int INF = 4294967295; //表示找不到

int main()
{
    while(cin>>s1>>s2)
    {
        int ans = s1.find(s2);
        if(ans == -1) printf("no\n");
        else printf("go\n");
    }
}

#include<stdio.h>
#include<string>
#include<iostream>
using namespace std;

string s1,s2;
const int INF = 4294967295; //表示找不到

int main()
{
    while(cin>>s1>>s2)
    {
        int ans = s1.find(s2);
        if(ans >= 0)printf("go\n");
        else printf("no\n");
    }
}


你可能感兴趣的:(BNU 26473 Aaah!【签到--->查找字符串】)