zoukankan      html  css  js  c++  java
  • 天梯---6翻了(模拟)

    “666”是一种网络用语,大概是表示某人很厉害、我们很佩服的意思。最近又衍生出另一个数字“9”,意思是“6翻了”,实在太厉害的意思。如果你以为这就是厉害的最高境界,那就错啦 —— 目前的最高境界是数字“27”,因为这是 3 个 “9”!

    本题就请你编写程序,将那些过时的、只会用一连串“6666……6”表达仰慕的句子,翻译成最新的高级表达。

    输入格式:

    输入在一行中给出一句话,即一个非空字符串,由不超过 1000 个英文字母、数字和空格组成,以回车结束。

    输出格式:

    从左到右扫描输入的句子:如果句子中有超过 3 个连续的 6,则将这串连续的 6 替换成 9;但如果有超过 9 个连续的 6,则将这串连续的 6 替换成 27。其他内容不受影响,原样输出。

    输入样例:

    it is so 666 really 6666 what else can I say 6666666666

    输出样例:

    it is so 666 really 9 what else can I say 27

    第一次 13分

     1 #include <cstdio>
     2 #include <iostream>
     3 #include <string>
     4 #include <algorithm>
     5 
     6 using namespace std;
     7 
     8 
     9 int main()
    10 {
    11     string str;
    12     int t=1;
    13     while(cin>>str)
    14     {
    15         if(str.find("6666666666")!=string::npos)
    16         {
    17             if(t)
    18             {
    19                 cout<<"27";
    20                 t=0;
    21             } 
    22             else cout<<" 27";
    23         }
    24         else if(str.find("6666")!=string::npos)
    25         {
    26             if(t)
    27             {
    28                 cout<<"9";
    29                 t=0;
    30             } 
    31             else cout<<" 9";
    32         }
    33         else 
    34         {
    35             if(t)
    36             {
    37                 cout<<str;
    38                 t=0;
    39             } 
    40             else cout<<" "<<str;
    41         }
    42     }
    43     return 0;
    44 }

    第二次 14分

     1 #include <cstdio>
     2 #include <iostream>
     3 #include <string>
     4 #include <algorithm>
     5 
     6 using namespace std;
     7 
     8 
     9 int main()
    10 {
    11     string str;
    12     getline(cin,str);
    13     int i,g;
    14     int len=0;
    15     for(i=0;i<=str.size();i++)
    16     {
    17         if(str[i]=='6') len++;
    18         else 
    19         {
    20             if(len>9) 
    21             {
    22                 if(str[i]) cout<<"27 ";
    23                 else cout<<"27";
    24             }
    25             else if(len>3) 
    26             {
    27                 if(str[i]) cout<<"9 ";
    28                 else cout<<"9";
    29             }
    30             else 
    31             {
    32                 for(g=0;g<len;g++) cout<<'6';
    33                 cout<<str[i];
    34             }
    35             len=0;
    36         }
    37     }
    38     return 0;
    39 }

    第三次 15分,终于AC了............

     1 #include <cstdio>
     2 #include <iostream>
     3 #include <string>
     4 #include <algorithm>
     5 
     6 using namespace std;
     7 
     8 
     9 int main()
    10 {
    11     string str;
    12     getline(cin,str);
    13     int i,g;
    14     int len=0;
    15     for(i=0;i<=str.size();i++)
    16     {
    17         if(str[i]=='6') len++;
    18         else 
    19         {
    20             if(len>9) 
    21             {
    22                 if(str[i]) cout<<"27"<<str[i];
    23                 else cout<<"27";
    24             }
    25             else if(len>3) 
    26             {
    27                 if(str[i]) cout<<"9"<<str[i];
    28                 else cout<<"9";
    29             }
    30             else 
    31             {
    32                 for(g=0;g<len;g++) cout<<'6';
    33                 cout<<str[i];
    34             }
    35             len=0;
    36         }
    37     }
    38     return 0;
    39 }
  • 相关阅读:
    Maven pom.xml中添加指定的中央仓库
    命令行远程链接MySQL
    A required class was missing while executing org.apache.maven.plugins:maven-war-plugin:2.1.1:war
    mvn deploy命令上传包
    保存好你的密码
    PuTTY免输密码自动登录Linux
    ActiveMQ无法启动
    linux控制台批量杀进程
    dubbo入门之微服务客户端服务端配置
    dubbo入门之helloWorld
  • 原文地址:https://www.cnblogs.com/jiamian/p/10646449.html
Copyright © 2011-2022 走看看