#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
using namespace std;
int main(void){
int n;
int top = 1;
int *words = new int[456976]; //最大為26的4次方
memset(words, 0, 456976 * sizeof(int)); //初始值為0
while (scanf("%d", &n) == 1){
for (int i = 0; i < n; i++){
char wd[5] = {0};
wd[0] = getchar();
wd[1] = getchar();
wd[2] = getchar();
wd[3] = getchar();
getchar();
//將字串轉成26進制的數字以方便搜尋
int idx = (wd[0] - 'a' + 1) + (wd[1] - 'a' + 1) * 26 +
(wd[2] - 'a' + 1) * (26 * 26) +
(wd[3] - 'a' + 1) * (26 * 26 * 26);
if (words[idx] == 0){
printf("New! %d\n", top);
words[idx] = top;
top++;
}
else
printf("Old! %d\n", words[idx]);
}
}
delete words;
return 0;
}
懇請高手提示一下ˊ.ˋ
#include
#include
#include
#include
using namespace std;
int main(void){
int n;
int top = 1;
int *words = new int[456976]; //最大為26的4次方
memset(words, 0, 456976 * sizeof(int)); //初始值為0
while (scanf("%d", &n) == 1){
for (int i = 0; i < n; i++){
char wd[5] = {0};
wd[0] = getchar();
wd[1] = getchar();
wd[2] = getchar();
wd[3] = getchar();
getchar();
//將字串轉成26進制的數字以方便搜尋
int idx = (wd[0] - 'a' + 1) + (wd[1] - 'a' + 1) * 26 +
(wd[2] - 'a' + 1) * (26 * 26) +
(wd[3] - 'a' + 1) * (26 * 26 * 26);
if (words[idx] == 0){
printf("New! %d\n", top);
words[idx] = top;
top++;
}
else
printf("Old! %d\n", words[idx]);
}
}
delete words;
return 0;
}
懇請高手提示一下ˊ.ˋ
wd[] - 'a' + 1 炸啦
矩陣要從0開始
#include
#include
#include
#include
using namespace std;
int main(void){
int n;
int top = 1;
int *words = new int[456976]; //最大為26的4次方
memset(words, 0, 456976 * sizeof(int)); //初始值為0
while (scanf("%d", &n) == 1){
for (int i = 0; i < n; i++){
char wd[5] = {0};
wd[0] = getchar();
wd[1] = getchar();
wd[2] = getchar();
wd[3] = getchar();
getchar();
//將字串轉成26進制的數字以方便搜尋
int idx = (wd[0] - 'a' + 1) + (wd[1] - 'a' + 1) * 26 +
(wd[2] - 'a' + 1) * (26 * 26) +
(wd[3] - 'a' + 1) * (26 * 26 * 26);
if (words[idx] == 0){
printf("New! %d\n", top);
words[idx] = top;
top++;
}
else
printf("Old! %d\n", words[idx]);
}
}
delete words;
return 0;
}
懇請高手提示一下ˊ.ˋ
wd[] - 'a' + 1 炸啦
矩陣要從0開始