• 剪花布条 2087


    Problem Description
    一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案。对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出几块小饰条来呢?
     
    Input
    输入中含有一些数据,分别是成对出现的花布条和小饰条,其布条都是用可见ASCII字符表示的,可见的ASCII字符有多少个,布条的花纹也有多少种花样。花纹条和小饰条不会超过1000个字符长。如果遇见#字符,则不再进行工作。
     
    Output
    输出能从花纹布中剪出的最多小饰条个数,如果一块都没有,那就老老实实输出0,每个结果之间应换行。
     
    Sample Input
    abcde a3 aaaaaa aa #
     
    Sample Output
    0 3
     
    Author
    qianneng
     
    Source
     
    Recommend
    lcy   |   We have carefully selected several similar problems for you:  1711 1686 3746 3336 1358 
     
     
     
    strstr应用:
     1 #include <stdio.h>
     2 #include <iostream>
     3 using namespace std;
     4 #include <string.h>
     5 int main()
     6 {
     7     char s[1024],a[1024];
     8     while(scanf("%s",&s)&&s[0]!='#'&&scanf("%s",&a))
     9     {
    10         int count=0;
    11         char *p=s;
    12         int len=strlen(a);
    13         while(p = strstr(p,a)){
    14             count++;
    15             p += len;
    16         }
    17         cout<<count<<endl;
    18     }
    19 }

    find应用:

     1 #include<iostream>
     2 #include<stdio.h>
     3 #include<string>
     4 #include<algorithm>
     5 using namespace std;
     6 int main()
     7 {
     8     string a,b;
     9     int pos,count=0;
    10     cin>>a;
    11     cin>>b;
    12 
    13      pos=a.find(b);//ccabcbbgabchuhiabc
    14     // cout<<pos<<endl;
    15     while(pos!=-1)
    16     { 
    17         count++;
    18        pos=a.find(b,pos+b.size());
    19         
    20     }
    21     cout<<count<<endl;
    22     return 0;
    23 }
  • 相关阅读:
    python 练习 10
    python 练习 9
    运算符
    变量类型
    打印更多的变量
    变量和命名
    数字和数字计算
    第一个程序
    python 练习 8
    python 练习 7
  • 原文地址:https://www.cnblogs.com/wangmengmeng/p/4640891.html
Copyright © 2020-2023  润新知