2945. Search Web Pages

RuiCMU
#include<iostream>
#include<string>
using namespace std;
int main(){


    string url[25];
    int v[25];
    int n,max=0;
     std::cin >> n;
    for(int i=0;i<n;i++){
        std::cin>> url[i] >> v[i];
        if(v[i]>max)
            max=v[i];
    }
    for(int i=0;i<n/2;i++){
        if(v[i]==max){
            std::cout << url[i] << std::endl;
        }
    }
    for(int i=n/2;i<n;i++){
        if(v[i]==max){
            std::cout << url[i] << std::endl;
        }
    }

}
Suzuki_Yuuta

map去记录相关系数和其对应的url,同时记录相关系数的最大值,这样就可以直接读到最大相关系数所对应的url了。

附上代码

#include <iostream>
#include <string>
#include <map>
#include <vector>
using namespace std;

void solve()
{
    int n; cin >> n; cin.ignore();
    map< int, vector<string> > data; int maxValue = 0;
    for (int i = 0; i < n; i++) {
        int value; string url;
        cin >> url >> value;
        if (maxValue < value) {
            maxValue = value;
        }
        if (data.find(value) == data.end()) {
            vector<string> temp;
            temp.push_back(url);
            data[value] = temp;
        } else {
            data[value].push_back(url);
        }
    }
    for (vector<string>::iterator it = data[maxValue].begin(); it != data[maxValue].end(); it++) {
        cout << *it <<endl;
    }
}
int main(int argc, char* argv[])
{
    solve();
    return 0;
}
BoxunWang

编译运行都行,就是提交后就是wrong answer,求大神帮忙

include

typedef struct Web{
char URL[100];
int vi;//1~100
}web;
int main()
{
int n, i, j = 1,k = 0;
web arr[20], *p[20];//0~20
p[0] = arr;

scanf("%d",&n);
for(i=0; i<n; i++)
    scanf("%s%d",arr[i].URL,&arr[i].vi);

for(i=0; i<n; i++)
    if(arr[i].vi > p[0]->vi)
    { p[0] = &arr[i]; k = j; j = 1;}
    else if(arr[i].vi == p[0]->vi)
    { p[j] = &arr[i]; j++; }

    for(i=0; i<=k; i++)
    printf("%s\n",p[i]->URL);
return 0;

}

Saitama
#include <bits/stdc++.h>
using namespace std;
typedef struct zz{string s;int t;int k;}zz;
vector <zz> arr(3614);
bool cmp(const zz &a,const zz &b)
{
    if(a.t==b.t)
        return a.k<b.k;
    else
        return a.t>b.t;
}
int main()
{
    int t;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        cin>>arr[i].s>>arr[i].t;
        arr[i].k=i;
    }
    sort(arr.begin(),arr.end(),cmp);
    int i;
    for(i=0;arr[i].t==arr[i+1].t;i++)
    {
        cout<<arr[i].s<<endl;
    }
    cout<<arr[i].s<<endl;
    return 0;
}

如果用点别的stl肯定更简单

10195101455

题目测试数据也太水了。。只配我这种水代码(哭唧唧)

include

using namespace std;

typedef struct
{
char url[101];
int vi;
}Web;

int main()
{
Web web[20];
int N;
cin>>N;
int n, max = 1;
for(n = 0; n < N; n++)
{
scanf(“%s%d”, web[n].url, &web[n].vi);
if(web[n].vi > max) max = web[n].vi;
}
for(n = 0; n < N; n++)
if(web[n].vi == max) cout<<web[n].url<<endl;
return 0;
}

Li Dao

这道题解法就是排序
但我这里用了优先队列

include

using namespace std;
struct webSite
{
int input;
string URL;
int V;
bool operator<(const webSite& bb) const
{
if(V!=bb.V) return Vbb.input;
}
};
int n;
priority_queue Q;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
string url;
int vv;
cin>>url>>vv;
Q.push((webSite){i,url,vv});
}

webSite Max=Q.top();
while(Q.top().V==Max.V)
{
  webSite tmp=Q.top();Q.pop();
  cout<<tmp.URL<<endl;
}

}

优先队列,大的在前面,所以重载运算符的时候,return那里符号反一下
但是operator<那里不要改,
而vector sort,如果要重载运算符,默认是小的在前面,return那里符号不用反

10165101104

怎么过不了??

include

include

using namespace std;

struct Node{
string s;
int m;
}a[21];

bool cmp(Node a,Node b)
{
return a.m>b.m;
}
int main()
{
int n;
cin >> n;
for(int i=0;i> a[i].s >> a[i].m;
}
sort(a,a+n,cmp);
for(int i=0;ia[i+1].m)
{
cout << a[i].s << endl;
break;
}
else
cout << a[i].s << endl;
}
return 0;
}

YZAZJL

include

include

using namespace std;
struct Web{
char url[101];
int num;
};
int main()
{
int n;
cin >> n;
Web web[n];
int max_rslt;
int i = 0;
cin >> web[i].url >> web[i].num;
max_rslt = web[i].num;
for(i = 1; i < n; i++){
cin >> web[i].url >> web[i].num;
if(web[i].num > max_rslt){
max_rslt = web[i].num;
}
}
for(i = 0; i < n; i++){
if(web[i].num == max_rslt){
cout << web[i].url << endl;
}
}
return 0;
}

热爱祖国热爱党

为啥用c语言写的程序用到了结构体排序就compile error,用c++交就能过,好神奇

include

include

include

include

struct Memory{
char brr[101];
int x;
};
int cmp(const void a,const void b){
return ((Memory )b).x > ((Memory )a).x ? 1 : -1;
}
int main(){
int T,i,y,j;
scanf(“%d\n”,&T);
char arr[T][105];
for(i=0;i<T;i++){
gets(arr[i]);
}
struct Memory crr[T];
for(i=0;i<T;i++){
y=strlen(arr[i]);
for(j=0;j<101;j++){
crr[i].brr[j]=’ ‘;
}
for(j=0;arr[i][j]!=’ ‘;j++){
crr[i].brr[j]=arr[i][j];
}
int a,b=y-j-2;
crr[i].x=0;
for(a=j+1;arr[i][a]!=’\0’;a++){
crr[i].x+=(arr[i][a]-‘0’)*(int)pow(10,b);
b–;
}
}

qsort(crr,T,sizeof(crr[0]),cmp);

for(i=0;i<T;i++){
    if(crr[i].x!=crr[i+1].x)
    break;
}
for(j=0;j<=i;j++){
    printf("%s\n",crr[j].brr);
}
return 0;

}

jxtxzzw

在线处理
不需要用数组保存所有网站
一边读一边记录,只保留最大值

#include <bits/stdc++.h>

using namespace std;

int main(){
    int max = - 0x3F3F3F3F;
    int n;
    int cnt = 0;
    string ss[20];
    scanf("%d", &n);
    while (n--!=0){
        string s;
        cin >> s;
        int w;
        cin >> w;
        if (w>max){
               cnt = 0;
            max = w;
            ss[cnt] = s;
            cnt++;
        } else if (w==max){
            ss[cnt] = s;
            cnt++;
        }

    }

    for (int i=0;i<cnt;++i){
        cout << ss[i] << endl;
    }

}
你当前正在回复 博客/题目
存在问题!