头像

Tequila


访客:899

离线:1天前



Tequila
10天前
#include<iostream>

using namespace std;

int main()
{
    string s1,s2;
    cin >> s1 >> s2;

    if(s1.size() < s2.size()) swap(s1,s2);
    for(int i = 0 ; i < s1.size(); i++)
    {   
        s1 = s1.substr(1) + s1[0];              // 去掉字符串第一位,ABCD;后加上字符串第一位,ABCDA
        for(int j = 0 ; j + s2.size() <= s1.size();j++)
        {                                       

            int k = 0 ;                         // [ B C D A A]  举例j+k所指位置和k所指位置,先移动长串后判断
                                                //   ^
                                                //  j+k
            for(; k < s2.size();k++)            // [ C D A A]   
            {                                   //   ^
                if(s1[j+k] != s2[k])            //   k
                    break;
            }

            if( k == s2.size())
            {
                cout << "true";
                return 0;
            }
        }
    }

    cout << "false";
    return 0;
}


活动打卡代码 AcWing 775. 倒排单词

Tequila
10天前
#include<iostream>
#include<string>
using namespace std;

int main()
{
    string s[100];
    int  n = 0;
    while(cin >> s[n] ) n++;

    for( int i  = n -1 ; i >= 0 ; i--)
    {
        cout << s[i] << ' ';
    }

    return 0;

}


活动打卡代码 AcWing 774. 最长单词

Tequila
12天前
#include<iostream>
#include<sstream>
#include<string>
using namespace std;

int main()
{
    string s,longstr;
    while(cin>>s)
    {
        if(s.back() == '.') s.pop_back();
        if(s.size() > longstr.size())
            longstr = s;
    }

    cout << longstr <<endl;

    return 0;

}



Tequila
12天前
#include<iostream>
#include<string>

using namespace std;

int main()
{
    int n ;
    cin >> n;
    string s;


    while(n --)
    {
        cin>>s;
        int max = 0;
        char num ;
        for(int i = 0 ; i < s.size() ; i++)
        {
            int j = i;
            while(j < s.size() && s[i] == s[j])
                j++;
            if( j - i > max)
            {
                max = j - i;
                num  = s[i];
            }
            i = j - 1; //如果i指向j的话,循环++就会跳过当前j所指位置
        }

        cout << num << ' ' << max <<endl ;
    }




    return 0;

}


活动打卡代码 AcWing 770. 单词替换

Tequila
12天前
#include<iostream>
#include<string>
#include<sstream>

using namespace std;

int main()
{   
    string s1,s2,s3;
    getline(cin,s1);
    cin >> s2 >> s3;

    stringstream ss(s1);

    while(ss>>s1)
        if(s1 == s2)
            cout << s3 << ' ';
        else 
            cout << s1 << ' ';


    return 0;
}



Tequila
12天前
#include<iostream>
#include<string>

using namespace std;

int main()
{
    string s;
    getline(cin,s);
    int len = s.size();
    char ans[len]; //开一个额外数组存题目所需要的字符
    int j = 0;
    for(int i  = 0 ; i+1   <= len ; i ++)
    {
        if((s[i] == ' ' && s[i+1] != ' ') || (s[i] != ' ')) //符合条件 存入数组中
            ans[j++] = s[i]; 

    }

    for(int k = 0; k < j; k++) 
    {
        cout << ans[k];
    }
    return 0;
}
}



Tequila
12天前
#include<iostream>
#include<string>

using namespace std;

int main()
{
    string s;
    getline(cin,s);
    int len = s.size();
    char ans[len];
    int j = 0;
    for(int i  = 0 ; i   < len ; i ++)
    {
        if((s[i] == ' ' && s[i+1] != ' ') || (s[i] != ' '))
            ans[j++] = s[i]; 

    }

    for(int k = 0; k < j; k++)
    {
        cout << ans[k];
    }
    return 0;
}


活动打卡代码 AcWing 764. 输出字符串

Tequila
14天前
#include<iostream>
#include<string>

using namespace std;

int main()
{
    string s1,s2;
    getline(cin,s1);

    int len1 = s1.size();

    for(int i = 0,k = 0 ; i < len1 ; i++,k++)
    {
     cout <<  (char) (s1[k] + s1[(k+1) % len1]);
    }


    return 0;

}


活动打卡代码 AcWing 767. 信息加密

Tequila
14天前
#include<iostream>
#include<string>
using namespace std;

int main()
{
    string str;
    getline(cin,str);

    for(int i = 0; i< str.size();i++)
    {
        if(str[i] >= 'a' && str[i] <='z') 
            str[i] = (str[i] - 'a' + 1) %26 + 'a';
        else if(str[i] >= 'A' && str[i] <='Z')
            str[i] = (str[i] - 'A'+ 1) %26 +'A'  ;
    }

    cout << str;
    return 0;
}



Tequila
14天前
#include<iostream>
#include<cstring>
#include<string>
using namespace std;

int main()
{   
    int  flag = 0;
    string s1,s2;
    getline(cin,s1);
    getline(cin,s2);
    int len1 =  s1.size();
    int len2 =  s2.size();
    for(int i = 0; i < max(len1,len2);i++)
    {
        if(s1[i] >= 'a' && s1[i] <= 'z')
            s1[i] -= 32 ;



        if(s2[i] >= 'a' && s2[i] <= 'z')
            s2[i] -= 32;
    }



    for(int k = 0;k < max(len1,len2);k++)
    {
        if(s1[k] == s2[k])
            flag = 0;
        else if(s1[k] > s2[k])
        {
            flag = 1;
            break;
        }
        else
        {
            flag = -1;
            break;
        }
    }

    if(flag == 0)
        cout << "=";
    else if (flag >0)
        cout << ">";
    else if (flag <0)
        cout << "<";
    return 0;

}