头像

小纸条o--o


访客:15949

离线:17天前



rt




blablabla

时间复杂度分析:blablabla

C++ 代码

#include<iostream>
#include<vector>
#include<stdio.h>
#include<string.h>
using namespace std;
int main(){
    char sentence[1024];
    scanf("%[^.]",&sentence);// .作为字符串输入的结束符
    char *tokenPtr=strtok(sentence," ");//sentence必须是一个char数组,不能是定义成指针形式
    vector<string> v;
    while(tokenPtr!=NULL){
        v.push_back(tokenPtr);
        tokenPtr= strtok(NULL," ");
    }
    string res=v.at(0);
    for (int i = 1; i < v.size(); ++i) {
        if(res.length()<v.at(i).length()){
            res=v.at(i);
        }
    }
    cout<<res<<endl;
    return 0;
}


算法2

(暴力枚举) $O(n^2)$

blablabla

时间复杂度分析:blablabla

C++ 代码

blablabla



题目描述

blablabla

样例

blablabla

C++ 代码

#include<iostream>
#include <ctime>

using namespace std;

int main() {
    struct tm t1 = { 0 };
    struct tm t2 = { 0 };
    int seconds;
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    t1.tm_hour=a;
    t1.tm_min=b;
    t2.tm_hour=c;
    t2.tm_min=d;

    seconds = difftime(mktime(&t2), mktime(&t1));//转换结构体为time_t,利用difftime,计算时间差
    if(seconds<=0){
        seconds+=86400;
    }
    int hour=seconds/3600;
    int min=(seconds%3600)/60;
    printf("O JOGO DUROU %d HORA(S) E %d MINUTO(S)\n",hour,min);
    return 0;
}


算法2

(暴力枚举) $O(n^2)$

blablabla

时间复杂度分析:blablabla

C++ 代码

blablabla



题目描述

blablabla

样例

blablabla

C++ 代码

#include<cstdio>
#include<iostream>
#include<string.h>
#include<vector>
#include<cstring>
#include<algorithm>
#include<math.h>
using namespace std;
int n;
void print(int i){
    int space=(n-i)/2;
    int star=i;
    for (int i = 0; i < space; ++i) {
        cout<<" ";
    }
    for (int i = 0; i < star; ++i) {
        cout<<"*";
    }
    for (int i = 0; i < space; ++i) {
        cout<<" ";
    }
    cout<<endl;

}


int main(){
    cin>>n;
    int flag=1;
    int k=1;
    for (int i = 1; k<=n; k++) {
        print(i);
        if(flag){
            i=i+2;
            flag=(i==n?0:1);

        }
        else{
            i=i-2;
            flag=(i==1?1:0);
        }

    }

    return 0;
}


算法2

(暴力枚举) $O(n^2)$

blablabla

时间复杂度分析:blablabla

C++ 代码

blablabla



题目描述

blablabla

样例

blablabla

C++ 代码

#include<cstdio>
#include<iostream>
#include<string.h>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;


int main(){

    char sentence[1024];
    scanf("%s",&sentence);
    char *tokenPtr=strtok(sentence,",");//sentence必须是一个char数组,不能是定义成指针形式
    string s[3];
    for (int i = 0; i < 3; ++i) {
        s[i]=tokenPtr;
        tokenPtr= strtok(NULL,",");
    }
    int pos=0;
    if((pos=s[0].find(s[1]))==string::npos){
        cout<<-1<<endl;
        return 0;
    }
    int pos1=0;
    if((pos1=s[0].rfind(s[2]))==string::npos){
        cout<<-1<<endl;
        return 0;
    }
  // cout<<pos<<"  "<<pos1<<endl;
    if(pos1-pos<=0||pos1-pos<s[1].length())
        {cout<<-1<<endl;
            return 0;
        }
    cout<<pos1-pos-s[1].length()<<endl;

    return 0;
}




题目描述

blablabla

样例

blablabla

C++ 代码

#include<cstdio>
#include<iostream>
#include<string.h>
#include<vector>
#include<algorithm>
using namespace std;
int n=0,mins=0;
vector<string> vec;
void fun(string &s){
    string last;
    for (int i = 1; i <= mins; ++i) {
        string tmp=vec.at(0).substr(vec.at(0).length()-i,vec.at(0).length());;
        for (int j = 1; j < vec.size(); ++j) {
            string  tmp1=vec.at(j).substr(vec.at(j).length()-i,vec.at(j).length());
            if(tmp!=tmp1)
            {
                i==1?s="":s=last;
                return;
            }
        }
       last=tmp; 
    }
    s=last;
}

int main(){
    while(cin>>n&&n!=0){
        vec.clear();
        mins=0x3f3f3f;
        for (int i = 0; i < n; ++i) {
            string str;
            cin>>str;
            mins=min(mins,(int)str.length());
            vec.push_back(str);
        }
        string s;
        fun(s);
        cout<<s<<endl;
    }
    return 0;
}





C++ 代码

#include<cstdio>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
int fun(const string &str){
    for (int i = 1; i <=str.length(); ++i) {
        string tmp=str.substr(0,i);
        int pre=0;
        int offindex = str.find(tmp, 0);
        pre=offindex;
        while (offindex != string::npos)
        {
            if(offindex+tmp.length()==str.length()){
                return str.length()/tmp.length();
            }
            offindex = offindex + 1;
            offindex = str.find(tmp, offindex); 
            if(offindex-pre!=tmp.length())
                break;
            pre=offindex;
        }
    }
    return str.length();
}

int main(){
    string a;
    while((cin>>a)&&a!="."){
        cout<<fun(a)<<endl;
    }
    return 0;
}


算法2

(暴力枚举) $O(n^2)$

blablabla

时间复杂度分析:blablabla

C++ 代码

blablabla



C++ 代码

#include<cstdio>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
int fun(string a,string b){
    int len=a.length();
    while(len--){
        if(a.find(b)!=string::npos){
            return 1;
        }
        a.push_back(a[0]);
        a.erase(a.begin());
    }
    return 0;
}
int main(){
    string a,b;
    cin>>a>>b;
    if(fun(a,b)||fun(b,a))
    cout<<"true"<<endl;
    else
    cout<<"false"<<endl;
    return 0;
}


算法2

(暴力枚举) $O(n^2)$

blablabla

时间复杂度分析:blablabla

C++ 代码

blablabla



C++ 代码

//unique函数属于STL中比较常用函数,它的功能是元素去重。
//即”删除”序列中所有相邻的重复元素(只保留一个)。此处的删除,并不是真的删除,
//而是指重复元素的位置被不重复的元素给占领了(详细情况,下面会讲)。由于它”删除”的是相邻的重复元素,所以在使用unique函数之前,
//一般都会将目标序列进行排序。
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    int arr[n];
    for (int i = 0; i < n; ++i) {
        cin>>arr[i];
    }
    sort(arr,arr+m);
    int length=unique(arr,arr+m)-arr;
    cout<<sizeof(arr)/sizeof(int)+length-m<<endl;
    return 0;
}




题目描述

blablabla

样例

blablabla

C++ 代码

#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
struct Node{
    int x;
    double y;
    char z[256];
    bool operator<(const Node& ps)const{
        if(this->x<ps.x)
            return true;
        else
            return false;
    }

};

int main(){
    int n;
    cin>>n;
    Node nodes[n];
    for (int i = 0; i < n; ++i) {
        int x;
        double y;
        char z[256];
        cin>>x>>y>>z;
        nodes[i].x=x;
        nodes[i].y=y;
        memcpy(nodes[i].z,z,sizeof(z));
    }
    sort(nodes,nodes+n);
    for (int i = 0; i < n; ++i) {
        cout<<nodes[i].x<<" ";
        printf("%.2f",nodes[i].y);
        cout<<" "<<nodes[i].z<<endl;
    }
    return 0;
}


算法2

(暴力枚举) $O(n^2)$

blablabla

时间复杂度分析:blablabla

C++ 代码

blablabla