头像

梦都会空




离线:6天前


最近来访(16)
用户头像
冰之韵
用户头像
lsz_
用户头像
追星星的人_6
用户头像
不想秃头
用户头像
低調ォ是王道
用户头像
miles2002
用户头像
hlf.
用户头像
獨孤求敗
用户头像
PUsg
用户头像
lviy_ptilopsis
用户头像
伽蓝音
用户头像
海问香
用户头像
konng0120
用户头像
转生到异世界当小镇做题家
用户头像
signed
用户头像
大雪莱


C++ 代码

//这个题目其实可以不需要二分,可以将其存入某个二维数组中即可
#include <iostream>
#include <cstring>

using namespace std;
int a[10005][2];
signed main()
{
    int n,m;
    cin>>n>>m;
    memset(a,-1,sizeof(a));
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        if(a[x][0]!=-1)
        {
            a[x][1]=i;
        }
        else
        {
            a[x][0]=i;
            a[x][1]=i;
        }
    }
    while (m -- ){
        int x;
        cin>>x;
        cout<<a[x][0]<<" "<<a[x][1]<<endl;
    }
}


活动打卡代码 AcWing 4482. 分组

//这里填你的代码^^
x = int(input())

lista = list(map(int,input().split()))

zda = {}
maxn = 0
for i in lista:
    if i not in zda:
        zda[i]=lista.count(i)
    else:
        continue
print(max(zda.values()))
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~


活动打卡代码 AcWing 1812. 方形牧场

梦都会空
2个月前
//这里填你的代码^^
#include <iostream>
#include <algorithm>

using namespace std;

signed main()
{
    int x1,x2,x3,x4,y1,y2,y3,y4;
    cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;
    int d = max(max(x2,x4) - min(x1,x3),max(y2,y4) - min(y1,y3));
    cout<<d*d<<endl;
    return 0;
}
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~


活动打卡代码 AcWing 1725. 组队井字游戏

梦都会空
2个月前
//这里填你的代码^^
#include <bits/stdc++.h>
using namespace std;
set<char> st1;
set<pair<char,char>> st2;
string a[3];
int dx[24]={0,0,0,1,1,1,2,2,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2},dy[24]={0,1,2,0,1,2,0,1,2,0,0,0,1,1,1,2,2,2,0,1,2,2,1,0};
int main(){
    int t=0;
    for(int i=0;i<3;i++){
        cin >> a[i];
    }
    for(int i=0;i<8;i++){ 
        int flag=0;
        char c=a[dx[t]][dy[t++]],tmp; 
        for(int j=1;j<3;j++){ 
            if(a[dx[t]][dy[t]]!=c){
                flag++;
                tmp=a[dx[t]][dy[t]];
            }
            t++;
        }
        if(!flag) st1.insert(c);
        else if(flag==1){ 
            if(!st2.count({tmp,c}))
                st2.insert({c,tmp});
        }
    }
    cout << st1.size()<< endl << st2.size()<<endl;
    return 0;
}
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~



梦都会空
3个月前

题目描述

这个题目其实不怎么难,直接说思路吧。首先读入一个数字,然后慢慢读入n个字符串,利用空格将每个单词提取出来放入列表中,然后利用三个字典将每个字符串第一个人的年龄求出来。上代码

python 代码

import random
# n, k = map(int, input().split())
# y = input()
# sum = 0
# zfc = ""
# f = 0
# bn = 1
# for i in range(len(y)):
#     if f == 0 and y[i] != " ":
#         zfc += y[i]
#     elif f == 0 and y[i] == " ":
#         f = 1
#     if f and y[i] == " ":
#         sum += 1
#         xzfc = zfc + " "
#         for j in range(i+1,len(y)):
#             #print(y[j])
#             if y[j] != " ":
#                 xzfc += y[j]
#             else:
#                 break
#         #print(xzfc,sum)
#         if len(xzfc) - sum > k:
#             print(zfc)
#             zfc = ""
#             sum = 0
#             bn = 1
#             f = 0
#         else:
#             zfc = xzfc
# print(zfc)

x = int(input())


sxb = {'Ox':0,'Tiger':1,'Rabbit':2,'Dragon':3,'Snake':4,'Horse':5,'Goat':6,'Monkey':7,'Rooster':8,'Dog':9,'Pig':10,'Rat':11}
sx = {'Bessie':'Ox'}
age = {'Bessie': 0}
while x:
    x = x - 1
    zfc = input()
    zf = ''
    lista = []
    for i in zfc:
        if i == ' ':
            lista.append(zf)
            zf = ''
        else:
            zf += i
    lista.append(zf)
    sx[lista[0]] = lista[4]
    if sx[lista[7]] == sx[lista[0]]:
        if lista[3] == 'previous':
            age[lista[0]] = age[lista[-1]] - 12
        else:
            age[lista[0]] = age[lista[-1]] + 12
    else:
        if lista[3] == 'previous':
            age[lista[0]] = age[lista[-1]] - (sxb[sx[lista[-1]]] - sxb[lista[4]] + 12) % 12
        else:
            age[lista[0]] = age[lista[-1]] + (sxb[lista[4]] - sxb[sx[lista[-1]]] + 12) % 12
print(abs(age['Elsie']))




活动打卡代码 AcWing 3370. 牛年

梦都会空
3个月前
//这里填你的代码^^
import random
# n, k = map(int, input().split())
# y = input()
# sum = 0
# zfc = ""
# f = 0
# bn = 1
# for i in range(len(y)):
#     if f == 0 and y[i] != " ":
#         zfc += y[i]
#     elif f == 0 and y[i] == " ":
#         f = 1
#     if f and y[i] == " ":
#         sum += 1
#         xzfc = zfc + " "
#         for j in range(i+1,len(y)):
#             #print(y[j])
#             if y[j] != " ":
#                 xzfc += y[j]
#             else:
#                 break
#         #print(xzfc,sum)
#         if len(xzfc) - sum > k:
#             print(zfc)
#             zfc = ""
#             sum = 0
#             bn = 1
#             f = 0
#         else:
#             zfc = xzfc
# print(zfc)

x = int(input())


sxb = {'Ox':0,'Tiger':1,'Rabbit':2,'Dragon':3,'Snake':4,'Horse':5,'Goat':6,'Monkey':7,'Rooster':8,'Dog':9,'Pig':10,'Rat':11}
sx = {'Bessie':'Ox'}
age = {'Bessie': 0}
while x:
    x = x - 1
    zfc = input()
    zf = ''
    lista = []
    for i in zfc:
        if i == ' ':
            lista.append(zf)
            zf = ''
        else:
            zf += i
    lista.append(zf)
    sx[lista[0]] = lista[4]
    if sx[lista[7]] == sx[lista[0]]:
        if lista[3] == 'previous':
            age[lista[0]] = age[lista[-1]] - 12
        else:
            age[lista[0]] = age[lista[-1]] + 12
    else:
        if lista[3] == 'previous':
            age[lista[0]] = age[lista[-1]] - (sxb[sx[lista[-1]]] - sxb[lista[4]] + 12) % 12
        else:
            age[lista[0]] = age[lista[-1]] + (sxb[lista[4]] - sxb[sx[lista[-1]]] + 12) % 12
print(abs(age['Elsie']))


//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~



梦都会空
3个月前

题目描述

这个题目其实还是比较简单的一种题目,直接说思路(所有语言通用)先遍历一下字符串将第一个单词存入一个字符串中,然后遇到一个空格之后将其加入其中,然后去遍历后面的字符,遇到空格停下来,再判断新字符串的长度(减去空格后)是否大于k,大于的话直接返回原来字符串,否则令原来字符串等于新字符串。

python代码

import random
n, k = map(int, input().split())
y = input()
sum = 0
zfc = ""
f = 0
bn = 1
for i in range(len(y)):
    if f == 0 and y[i] != " ":
        zfc += y[i]
    elif f == 0 and y[i] == " ":
        f = 1
    if f and y[i] == " ":
        sum += 1
        xzfc = zfc + " "
        for j in range(i+1,len(y)):
            #print(y[j])
            if y[j] != " ":
                xzfc += y[j]
            else:
                break
        #print(xzfc,sum)
        if len(xzfc) - sum > k:
            print(zfc)
            zfc = ""
            sum = 0
            bn = 1
            f = 0
        else:
            zfc = xzfc
print(zfc)


活动打卡代码 AcWing 1442. 单词处理器

梦都会空
3个月前
//这里填你的代码^^
import random
n, k = map(int, input().split())
y = input()
sum = 0
zfc = ""
f = 0
bn = 1
for i in range(len(y)):
    if f == 0 and y[i] != " ":
        zfc += y[i]
    elif f == 0 and y[i] == " ":
        f = 1
    if f and y[i] == " ":
        sum += 1
        xzfc = zfc + " "
        for j in range(i+1,len(y)):
            #print(y[j])
            if y[j] != " ":
                xzfc += y[j]
            else:
                break
        #print(xzfc,sum)
        if len(xzfc) - sum > k:
            print(zfc)
            zfc = ""
            sum = 0
            bn = 1
            f = 0
        else:
            zfc = xzfc
print(zfc)
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~



梦都会空
3个月前
//这里填你的代码^^
#include <iostream>
#include <cstring>

using namespace std;
int a[27];

signed main()
{
    string s;
    cin>>s;
    for(int i=0;i<26;i++) a[s[i]-'a'] = i;
    cin>>s;
    int sum =1;
    for(int i=1;i<s.size();i++)
    {
        if(a[s[i]-'a'] <= a[s[i-1]-'a']) sum++;
    }
    cout<<sum<<endl;
}
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~


活动打卡代码 AcWing 1459. 奶牛体操

梦都会空
3个月前
//这里填你的代码^^
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
int a[21];
int b[21][21];
signed main()
{
    int n,m;
    cin>>m>>n;
    for(int l=0;l<m;l++)
    {
        for (int j = 1; j <= n; j++) scanf("%d", &a[j]);
        for (int j = 1; j < n; j++)
            for (int x = j + 1; x <= n; x++) b[a[j]][a[x]]++;

    }
     int ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) if (b[i][j] == m) ans++;
    } printf("%d\n", ans);
}
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~