zoukankan      html  css  js  c++  java
  • CF 798B 渣渣题

    题目链接:http://codeforces.com/contest/798/problem/B

    此题是我打河工大校赛前一晚熬夜打CF时硬肛过去的B题,今天补题时,偶然看到dalao的代码,ORZ,string和find函数的用法学到了。啦啦啦

    虽然,那天现场赛炸了,但并不影响我的可爱呀,略略略!!

     1 #include<string>
     2 #include<cstdio>
     3 #include<iostream>
     4 using namespace std;
     5 int main()
     6 {
     7     string  temp,ch[55];
     8     int n,ans=0x3f3f3f3f,count=0;
     9     cin>>n;
    10     for(int i=0;i<n;i++)  cin>>ch[i];
    11     for(int i=0;i<n;i++)
    12     {
    13         count=0;
    14         for(int j=0;j<n;j++)  
    15         {
    16             temp=ch[j]+ch[j];        //如果要处理首尾,循环的问题,再加一次是很好的选择
    17 16             //如果发现不了这样的字符串,这个find会等于string::npos(可以看作的很大的数 ) 
    18             if(temp.find(ch[i])==string::npos)  
    19             {
    20                 printf("-1
    "); return 0;
    21             }
    22             count+=temp.find(ch[i]);  //发现相同字符串的头位置
    23         }
    24         ans=min(ans,count);
    25     }
    26     printf("%d
    ",ans);
    27     return 0;
    28 }
  • 相关阅读:
    CSS左侧固定宽 右侧自适应(兼容所有浏览器)
    MySQL学习笔记之一
    删除goagnt证书方法〔chrome
    JS通过ajax动态读取xml文件内容
    display vs visibility
    android SDK更新
    关于JS APP
    Ajax HTML, JS
    Request/Server模式
    关于SOAP
  • 原文地址:https://www.cnblogs.com/weimeiyuer/p/6809406.html
Copyright © 2011-2022 走看看