1. 程式人生 > >SDNU 1533 尋找復讀機

SDNU 1533 尋找復讀機

本質 turn cst 一份 正整數 temp pac long class

Description

某小隊裏一共有 n 個人,他們的編號是 1..n,其中有一些人本質上是復讀機。 底層群員柳予欣發現,如果一個人的本質是復讀機,那麽他每次發的消息一定跟群裏的上一條消息一樣,特別地第一個發消息的人一定不是復讀機。 某不願透露姓名的管理員現在搞到了一份聊天記錄,他想請你找出所有可能是復讀機的群友。 技術分享圖片

Input

多組輸入。 每組輸入的第一行兩個正整數 n,m,表示群裏的人數和聊天記錄的總條數。 接下來 m 行按時間順序給出聊天記錄,每行有一個正整數 x 和一個小寫字母字符串 S,表示群友 x 發了消息 S。 1≤ n≤ 1000 1≤ m≤ 1000
#include <cstdio>
#include 
<iostream> #include <algorithm> #include <string> #include <cstring> #include <cmath> using namespace std; #define ll long long int main() { char str[1010][110]; int ans[1010], a, x, n, m, j, temp; while (~scanf("%d%d", &n, &m)) { temp = 0;//控制空格輸出
memset(ans, 0, sizeof(ans));//設每個人都是復讀機 scanf("%d%s", &a, str[0]); for (int i = 1; i < m; i++) { scanf("%d%s", &x, str[i]);//第x個人的復讀情況 if (strcmp(str[i], str[i - 1])) ans[x] = 1;//若不是復讀機,則單獨標記 } ans[a] = 1;//特別的,第一個肯定不是復讀機 for
(int i = 1; i <= n; i++) if (!ans[i])//如果是復讀機 { if (temp)//控制空格 printf(" "); temp = 1; printf("%d", i); } printf("\n"); } return 0; }

1≤ |S|≤ 100

Output

輸出一行,將所有可能是復讀機的群友的編號按照從小到大排序後輸出,每兩個編號之間隔一個空格。

Sample Input

3 5
1 gugugu
2 gugugu
1 gugu
3 tingzhifudu
2 tingzhifudu

Sample Output

2

SDNU 1533 尋找復讀機