Topic Portal
1 /*2 Test Instructions: Give a series of name changes, ask what the last name became3 string Processing: Each time the input to the previous name of the printing, if not, it is the initial, Pos[m] array record the initial position4 the initial POS is added to each update, so the initial name is guaranteed to be updated, which is the only place to think about:)5 */6#include <cstdio>7#include <iostream>8#include <cstring>9#include <algorithm>Ten#include <cmath> One#include <string> A#include <map> -#include <ctime> - using namespacestd; the - Const intMAXN = 1e3 +Ten; - Const intINF =0x3f3f3f3f; - stringOLD[MAXN]; + stringCHANGE[MAXN]; - stringANS[MAXN]; + intPOS[MAXN]; A at intMainvoid)//codeforces Round #285 (Div. 2) b. Misha and changing Handles - { -Freopen ("b.in","R", stdin); - - intN; - while(SCANF ("%d", &n) = =1) in { -memset (POS,0,sizeof(POS)); to stringtmpintm =0; + for(intI=1; i<=n; ++i) - { theCIN >> TMP; CIN >>Change[i]; * BOOLOK =false; $ for(intj=1; j<i; ++j)Panax Notoginseng { - if(TMP = =Change[j]) the { +OK =true; AANS[POS[J]] =Change[i]; thePos[i] = Pos[j]; Break; + } - } $ if(!OK) $ { -OLD[++M] = tmp; ANS[M] = Change[i]; Pos[i] =m; - } the } - Wuyiprintf ("%d\n", m); the for(intI=1; i<=m; ++i) - { Wucout << Old[i] <<" "<< Ans[i] <<Endl; - } About } $ - //cout << "Time:" << (double) clock ()/clocks_per_sec * + << "ms\n"; - - return 0; A}
String processing codeforces Round #285 (Div. 2) b. Misha and changing Handles