#19017: 用pair解!


089487 (089487)

學校 : 國立臺灣師範大學附屬高級中學
編號 : 82069
來源 : [220.130.10.185]
最後登入時間 :
2024-04-01 11:16:18
d710. parking lot -- 葆葆 | From: [223.140.74.27] | 發表日期 : 2019-08-26 11:57

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int t,t2;
while(cin>>t>>t2)
{
string a;
pair <string,string> p[t];
// pair <string,string> p2[t];
for(int i=0;i<t;i++)
{
cin>>a;
p[i].first=a;
// p2[i].second=a;
cin>>a;
p[i].second=a;
// p2[i].first=a;
}
// sort(p,p+t);
// sort(p2,p2+t);
string key,s;
for(int i=0;i<t2;i++)
{
//bool f;
cin>>key>>s;
if(key=="brand")
{
//sort(p,p+)
// f=false;
for(int i=0;i<t;i++)
{
if(p[i].first==s) cout<<p[i].first<<" "<<p[i].second<<endl;
//else if(f) break;
}
}
else if(key=="color")
{
//sort(p,p+)
//f=false;
for(int i=0;i<t;i++)
{
if(p[i].second==s) cout<<p[i].first<<" "<<p[i].second<<endl;
}
}
}
}
}

AC (2ms, 328KB)
 
#19021: Re:用pair解!


ufve0704 (爬 我爬 我爬爬爬 有排行榜這種東西就是要爬 爬過我上面的那...)

學校 : 臺北市私立延平高級中學
編號 : 83268
來源 : [203.72.178.1]
最後登入時間 :
2023-10-30 13:02:50
d710. parking lot -- 葆葆 | From: [114.42.212.117] | 發表日期 : 2019-08-26 15:10

#include
#include
using namespace std;
int main()
{
int t,t2;
while(cin>>t>>t2)
{
string a;
pair <string,string> p[t];
// pair <string,string> p2[t];
for(int i=0;i<t;i++)
{
cin>>a;
p[i].first=a;
// p2[i].second=a;
cin>>a;
p[i].second=a;
// p2[i].first=a;
}
// sort(p,p+t);
// sort(p2,p2+t);
string key,s;
for(int i=0;i<t2;i++)
{
//bool f;
cin>>key>>s;
if(key=="brand")
{
//sort(p,p+)
// f=false;
for(int i=0;i<t;i++)
{
if(p[i].first==s) cout<<p[i].first<<" "<<p[i].second<<endl;
//else if(f) break;
}
}
else if(key=="color")
{
//sort(p,p+)
//f=false;
for(int i=0;i<t;i++)
{
if(p[i].second==s) cout<<p[i].first<<" "<<p[i].second<<endl;
}
}
}
}
}

AC (2ms, 328KB)

其實用陣列更簡單XDD

#include<bits/stdc++.h>

using namespace std;

int main(){

int a,b;

while(cin>>a>>b){

string c[a],d[a];

for(int e=0;e<a;e++)

cin>>c[e]>>d[e];

for(int e=0;e<b;e++){

string f,g;

cin>>f>>g;

if(f=="color"){

for(int h=0;h<a;h++)

if(d[h]==g)

cout<<c[h]<<' '<<d[h]<<endl;

}

else{

for(int h=0;h<a;h++)

if(c[h]==g)

cout<<c[h]<<' '<<d[h]<<endl;

}

}

}

}

 

 
#34669: Re: 用pair解!


alex950301 (alex0301)

學校 : 新北市立新莊高級中學
編號 : 141423
來源 : [61.64.1.159]
最後登入時間 :
2024-05-03 23:38:53
d710. parking lot -- 葆葆 | From: [210.71.72.210] | 發表日期 : 2023-04-06 19:32

#include
#include
using namespace std;
int main()
{
int t,t2;
while(cin>>t>>t2)
{
string a;
pair p[t];
// pair p2[t];
for(int i=0;i {
cin>>a;
p[i].first=a;
// p2[i].second=a;
cin>>a;
p[i].second=a;
// p2[i].first=a;
}
// sort(p,p+t);
// sort(p2,p2+t);
string key,s;
for(int i=0;i {
//bool f;
cin>>key>>s;
if(key=="brand")
{
//sort(p,p+)
// f=false;
for(int i=0;i {
if(p[i].first==s) cout< //else if(f) break;
}
}
else if(key=="color")
{
//sort(p,p+)
//f=false;
for(int i=0;i {
if(p[i].second==s) cout< }
}
}
}
}

AC (2ms, 328KB)

其實用陣列更簡單XDD

#include

using namespace std;

int main(){

int a,b;

while(cin>>a>>b){

string c[a],d[a];

for(int e=0;e

cin>>c[e]>>d[e];

for(int e=0;e

string f,g;

cin>>f>>g;

if(f=="color"){

for(int h=0;h

if(d[h]==g)

cout<

}

else{

for(int h=0;h

if(c[h]==g)

cout<

}

}

}

}

 

用map會輕鬆XD

#include <iostream>
#include <vector>
#include <map>
using namespace std;
int main() {
    int n , m ;
    while( cin >> n >> m ) {
        map< string , vector<string> > mp1 ;
        map< string , vector<string> > mp2 ;
        
        string a , b ;
        for( int i = 0 ; i < n ; i++ ) {
            cin >> a >> b ;
            mp1[a].push_back( b ) ;
            mp2[b].push_back( a ) ;
        }
        
        string x , y ;
        for( int i = 0 ; i < m ; i++ ) {
            cin >> x >> y ;
            if( x == "brand" ) {
                for( auto it : mp1[y] ) {
                    cout << y << " " << it << endl ;
                }
            } else if( x == "color" ) {
                for( auto it : mp2[y] ) {
                    cout << it << " " << y << endl ;
                }
            }
        }
        cout << endl ;
    }
    return 0;
}

 
ZeroJudge Forum