missall <- c("")
#各種類型範例
#missall <- c("森","土.腐","火.貓又","青鷺","護.水","御琴.雪女","木傭兵.山道","涼香.黃泉")
diffi <- c("初", "森", "腐", "草", "昏", "書家", "淵", "一夏", "女子", "死者", "" , "中" , "山道", "泉", "慘劇", "聖", "炎", "雪", "廢村", "前篇", "後篇", "", "上", "山彥", "妻", "堕", "書", "夏", "溫泉", "黃泉", "山水", "天空" , "" , "其他" )
loc <- c("白龍(昏13 死者3 前篇123 天空134)","海葵(一夏2)","網切(腐123 山彥3 堕12)","神(黃泉134)",
"阿形(山道23 龍神234)","紅毛(淵123 前篇23)","貓又(慘劇4 狐二1234)","大骷髏(黃泉134 後篇4)","黑牛(女子23 後篇2)",
"雞(炎12 天空34)","妖精(書23)","野槌(堕4)","毛怪(山彥4 妖姬1234)","黃泉戰(黃泉13)","狼(草123)",
"蔓(草23 狐一2 狐二3)","骸骨(死者23 後篇123)","猩猩(聖123)","藍牛(女子23 昏13 聖123 前篇123 後篇123 天空34)",
"骨武(黃泉13 前篇4 後篇234)","哞(山道23 龍神234)","山地乳(溫泉4)","馬頭(黃泉24)",
"青鷺(妻234 堕3 天空45)","魅魔(書234)","紅鬼(山道4 狐一4 鬼1 後篇3 狐二4 妖姬3)","牛頭(黃泉24)","餓鬼(腐4 狐一24 鬼1)",
"露草(鬼35)","河童(淵4 狐二1234)","紅蛇(草123 聖123 前篇23)","岩魚(昏13 淵123 炎23 一夏234)","五德(慘劇123 堕2)",
"人虎(山水345 炎3 狐一34 狐二234)","蝦蟆(泉123 狐一4 狐二123)","白婆(雪123)","白貓(慘劇123 山彥3)","小豆(夏23)",
"牛鬼(龍神123)","牡丹(鬼45)","白狐(死者13 堕123 山彥3)","山椒魚(昏4 狐一34 狐二1234)","小袖(書家123)",
"大煙狸(廢村3 七4)","油(廢村4 妖姬123)","冰女(雪1234)","蟹(溫泉1234 一夏5)","唐傘(夏23)","橋姬(夏4)",
"文狸(夏23)","人魚(一夏1)","雪女(雪4 妖姬123)","飛緣(炎4 妖姬123)","姑獲(妻234 堕3 天空45)","古樁(死者4 狐二4 妖姬123)",
"座敷(百鬼10 15 18 21)","大王花(書23)","手目(泉123 山彥3)","赤殿(泉123 炎2 廢村3)","影女(書家123 廢村1)","雪子(雪1234)",
"否哉(炎23 龍神1 廢村1)","娼妓(廢村234 堕12)","二口(廢村134 堕12)","貝殼(一夏34)","頭顱(百鬼123)","榮螺(夏2)","蝶化身(草8)",
"文車(書家8)","鬼女(鬼10)","濡女(腐8)","一目(書家4 堕4 狐一3 狐二1234)","蜘蛛(森4 堕3 狐一1 狐二23)",
"提燈(夏23)","經凜(溫泉1234 書34)","姑鳥(妻234 堕3 天空45)","犬(女子4 淵123 山道1 聖123 炎3 前篇123 天空34)",
"樹(森2 狐一1 狐二23)","入道(炎123 狐二1234)","章魚(聖4 狐二1234 妖姬34)","分狸(聖123 泉123 夏1 七4 廢村23 百鬼123)",
"花子(山彥3 七12)","蜜蜂(書234)","鰻魚(昏2 夏2 狐一34 狐二123)","小鼠(森13 炎1)","鐮鼬(一夏34 森13 妻23 天空34)",
"黏液(泉4 狐二1234)","天狗(妻4 狐二4 妖姬1234 天空4)","紅燈(山彥13 炎2 百鬼123)","雲鏡(書家123 炎3 堕4 廢村2)",
"鼬鼠(一夏234 森13)","木棉(死者13 百鬼12 天空14)","貘(書1)","白蛇(夏3)","火車(炎123 慘劇123 堕4 天空34)",
"魍魎(女子123 腐23 山彥2 堕3 龍神23)","狒狒(堕3 狐一34 龍神3 七1 狐二23)","仙狸(山水345)","管狐(森13)",
"野衾(炎23 狐二124 妖姬3 天空45)","殭屍(山水134)","小傘(腐123 炎23 山彥1 夏1 百鬼12)","小狗(森13 書家123)","立衣(山道123)",
"泥田(腐23 狐一14)","鐵鼠(死者23 山道3 山彥2 前篇23)","大蛇(草4 狐一2 狐二234)","一眼(雪123)","舊鼠(山道123 山彥2)",
"豹(山水1345)","枕頭(書14 溫泉1234)","金花貓(山水345)","魑魅(女子123 腐23 山彥2 堕3 龍神23)","垢嘗(廢村3 妖姬123)",
"古物(夏2)","紅泥(死者2)","敷次郎(後篇1234)","木葉(妻1234 天空34)","藍牆(百鬼4)","山男(妻13)","泣爺(夏1)",
"八咫烏(死者13 天空13)","模型(七12)","天邪鬼(七2 鬼1 狐二4)","娃娃(七12)","猿(龍神13)","綠狗(妻1234)","護士(七6789)",
"八尺(七6789)","青龍(龍神5)","半身(七9)","禍斗(山水5)","裂口(七9)","古狸(七4 妖姬1234)","大神(黃泉4)","產女(黃泉13)",
"栞(書4)","向日葵(鬼25)","狂歌(妖姬4)","朝香(七5)","小夜(龍神4)","水妖(溫泉1234 墮1234)","惡魔蟲(山水134)","網剪(黃泉13)",
#"蝙蝠(魔一234 魔二5 魔三13)","狼人(魔一134 魔三13)","木乃伊(魔一34 魔三13)","黑騎士(魔一5 魔三13)","堕天使(魔三4)",
#"蜘蛛女(魔二13 魔三23)","紅花(魔二23 魔三3)","石像鬼(魔二13 魔三23)","樹精(魔二4 魔三234)","女妖(魔二23 魔三23)",
#"美人魚(魔二23 魔三23)","舞姬(魔二13 魔三3)","天使(魔二3 魔三2)","水龍(魔三134)","夢魔女(魔三34)","蜃(魔三234)",
"付喪神(書1)","辻神(山彥1 堕3 龍神123)","鈴彥(女子8)","伊織(山水2)","雀(溫泉123 天空45)","白兔(月4)","白蛇神(溫泉8)",
#"空(天空2)","七歌(天空2)",
"鶴女房(雪56)","雪天狗(雪56 妻567)","氷鬼(雪56)","","","","","","","","","","","","","","","","","","","","","","","","","","","","","")
kagura <- function(mis){
result <- 0
numct <- 1
##############################################位置
for(i in 1:length(loc)){
n <- nchar(loc[i])
for(k in 1:n){
if(substr(loc[i],start=k,stop=k) == "("){
name <- substr(loc[i],1,k-1)
mis <- gsub(name,loc[i],mis)
}
}
}
for(i in 1: length(mis)){
lenm <- nchar(mis[i])
lenmchr <- substr(mis[i],start=lenm,stop=lenm)
lenmchr2 <- substr(mis[i],start=lenm-1,stop=lenm-1)
if(
(lenmchr == "1" || lenmchr == "2" || lenmchr == "3" || lenmchr == "5")
&& (lenmchr2 != "金" && lenmchr2 != "木" && lenmchr2 != "水" && lenmchr2 != "火" && lenmchr2 != "土")
){
for(j in lenm:1){
if(substr(mis[i],start=j,stop=j) == "("){
mis[i] <- paste0(substr(mis[i],1,j-1),substr(mis[i],start=lenm,stop=lenm),substr(mis[i],start=j,stop=lenm-1))
break
}
}
}
if(numct == 1){
cat("初\n")
}
#if(numct == 8){ 20211002中間休息期間任務簡化了
if(numct == 6){
cat("中\n")
}
#if(numct == 17){
if(numct == 12){
cat("上\n")
}
numct = numct+1
#if(numct == 8 || numct == 17 || numct == 25 || numct == 34){
if(numct == 6 || numct == 12 || numct == 19 || numct == 34){
cat(mis[i])
cat("\n\n")
}else{
cat(mis[i]," ")
}
}
cat("\n\n")
##############################################
for(i in 1:length(mis)){
n <- nchar(mis[i])
type <- 1 #1=clear, 2=.clear, 2.2=.tar, 3=+, 4=.attr
##############################################類型判斷
for(j in 1:n){
if(substr(mis[i],start=j,stop=j) == "."){
type <- 2
for(m in (j+1):n){
if(substr(mis[i],start=m,stop=m) == "("){
type <- 2.2
break
}
}
break
}
}
if(type != 2 && type != 2.2){
for(k in 1:n){
if(substr(mis[i],start=k,stop=k) == "("){
type <- 3
break
}
}
}
for(l in (n-1):n){
if(substr(mis[i],start=l,stop=l) == "金" || (substr(mis[i],start=l,stop=l) == "水" && substr(mis[i],start=l-1,stop=l-1) != "山") || substr(mis[i],start=l,stop=l) == "木" || substr(mis[i],start=l,stop=l) == "火" || substr(mis[i],start=l,stop=l) == "土"){
type <- 4
break
}
}
##############################################寫成整理版形式
if(type == 1){
result[i] <- paste0(mis[i],"(通關)")
}
if(type == 2){
result[i] <- paste0(strsplit(mis[i],split=".",fixed=T)[[1]][2],"(",strsplit(mis[i],split=".",fixed=T)[[1]][1],")")
}
if(type == 2.2){
nz <- nchar(mis[i])-1
for(z in m+2:nchar(mis[i])-1){
if(substr(mis[i],z,z) == " "){
nz <- z-1
break
}
}
if(substr(mis[i],start=m+2,stop=m+2) == "1" || substr(mis[i],start=m+2,stop=m+2) == "2" || substr(mis[i],start=m+2,stop=m+2) == "3" || substr(mis[i],start=m+2,stop=m+2) == "4" ){
#result[i] <- paste0(substr(mis[i],start=m+1,stop=m+1),"(",mis[i],")")
#result[i] <- paste0(substr(mis[i],start=m+1,stop=m+1),"(",substr(mis[i],start=1,stop=m-1),substr(mis[i],start=m+2,stop=nchar(mis[i])-1),")")
result[i] <- paste0(substr(mis[i],start=m+1,stop=m+1),"(",substr(mis[i],start=1,stop=m-1),substr(mis[i],start=m+2,stop=nz),")")
}else{
#result[i] <- paste0(substr(mis[i],start=m+1,stop=m+2),"(",substr(mis[i],start=1,stop=m-1),substr(mis[i],start=m+3,stop=nchar(mis[i])-1),")")
result[i] <- paste0(substr(mis[i],start=m+1,stop=m+2),"(",substr(mis[i],start=1,stop=m-1),substr(mis[i],start=m+3,stop=nz),")")
}
}
if(type == 3){
nz <- nchar(mis[i])-1
for(z in k+2:nchar(mis[i])){
if(substr(mis[i],z,z) == " "){
nz <- z-1
break
}
}
if(substr(mis[i],start=k+2,stop=k+2) == "1" || substr(mis[i],start=k+2,stop=k+2) == "2" || substr(mis[i],start=k+2,stop=k+2) == "3" || substr(mis[i],start=k+2,stop=k+2) == "4" ){
#result[i] <- paste0(substr(mis[i],start=k+1,stop=k+1),"(",substr(mis[i],start=1,stop=k-1),"+",substr(mis[i],start=k+2,stop=n-1),")")
result[i] <- paste0(substr(mis[i],start=k+1,stop=k+1),"(",substr(mis[i],start=1,stop=k-1),"+",substr(mis[i],start=k+2,stop=nz),")")
}else{
#result[i] <- paste0(substr(mis[i],start=k+1,stop=k+2),"(",substr(mis[i],start=1,stop=k-1),"+",substr(mis[i],start=k+3,stop=n-1),")")
result[i] <- paste0(substr(mis[i],start=k+1,stop=k+2),"(",substr(mis[i],start=1,stop=k-1),"+",substr(mis[i],start=k+3,stop=nz),")")
}
}
if(type == 4){
result[i] <- mis[i]
}
}
#######################################################分出非其他
trueresult <- 0
n <- 1
for(ri in 1:length(diffi)){
for(rj in 1 : length(result)){
if(substr(result[rj],start=2,stop=2) != "." && substr(result[rj],start=2,stop=2) != "(" && substr(result[rj],start=3,stop=3) != "."){
if(substr(result[rj],start=1,stop=2) == diffi[ri]){
trueresult[n] <- result[rj]
n <- n+1
}
}else{
if(substr(result[rj],start=1,stop=1) == diffi[ri]){
trueresult[n] <- result[rj]
n <- n+1
}
}
}
}
#######################################################非其他排序
for(i in 1:length(result)){
for(j in 1:length(trueresult)){
if(!is.na(trueresult[j])){
if(result[i] == trueresult[j]){
result[i] <- 1
}
}
}
}
trueresult2 <- 0 #8/10i=j時有誤 8/13修正
for(i in 1:length(trueresult)){
for(j in 1:length(diffi)){
if(substr(trueresult[i],start=1,stop=1) == diffi[j] || substr(trueresult[i],start=1,stop=2) == diffi[j]){
#trueresult2[j] <- paste0(trueresult2[j],trueresult[i])
if(is.na(trueresult2[j])){
trueresult2[j] <- paste0(trueresult2[j],trueresult[i])
}else{
if(substr(trueresult[i],start=1,stop=1) == diffi[j]){
trueresult2[j] <- paste0(substr(trueresult2[j],start=1,stop=nchar(trueresult2[j])-1)," ",substr(trueresult[i],start=3,stop=nchar(trueresult[i])-1),")")
}else{
trueresult2[j] <- paste0(substr(trueresult2[j],start=1,stop=nchar(trueresult2[j])-1)," ",substr(trueresult[i],start=4,stop=nchar(trueresult[i])-1),")")
}
}
break #8/31避免書家的重複到書
}
}
}
trueresult <- trueresult2
trueresult[1] <- "初"
trueresult[11] <- ""
trueresult[12] <- "中"
trueresult[22] <- ""
trueresult[23] <- "上"
trueresult[33] <- ""
trueresult[34] <- "其他"
#trueresult <- sub("0",replacement="NA",trueresult)
#######################################################輸出
for(i in 1:length(trueresult)){
if(!is.na(trueresult[i]) && trueresult[i] != "NA"){
if(substr(trueresult[i],1,2) == "NA"){
trueresult[i] <- substr(trueresult[i],3,nchar(trueresult[i]))
}
cat(trueresult[i])
cat("\n")
}
}
for(i in 1:length(result)){
if(result[i] != 1){
cat(result[i])
cat("\n")
}
}
}
kagura(missall)