題目連結: https://zerojudge.tw/ShowProblem?problemid=d517
# 解題思路
用 map 紀錄出現的次數就好啦!!
# 程式碼
#include<bits/stdc++.h> | |
using namespace std; | |
int main(){ios::sync_with_stdio(false); | |
int n; | |
while(cin>>n) | |
{ | |
map<string,int>m; | |
string s; | |
int r=1; | |
for(int i=0;i<n;i++) | |
{ | |
cin>>s; | |
if(!m[s]){ | |
m[s]=r++; | |
cout<<"New! "<<m[s]<<endl; | |
} | |
else | |
cout<<"Old! "<<m[s]<<endl; | |
} | |
} | |
} |