Last active
December 19, 2015 17:19
-
-
Save fantasticswallow/5990632 to your computer and use it in GitHub Desktop.
C言語のなんか
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <ctype.h> | |
#include <string.h> | |
char charAddition(char ref, int num); | |
int charValid(char ref); | |
int charContains(char tag,char ref[]); | |
void main() | |
{ | |
char name[100]; | |
char name2[100]; | |
char name3[100]; | |
int dict[26]; | |
char baseAlpha[6]; | |
int alpDiff; | |
int isValid; | |
int i; | |
int i2; | |
int iLoopable; | |
int cRes; | |
int maxVowelCount = 0; | |
int curVowel; | |
char cacheChar1,cacheChar2; | |
printf("ローマ字表記の日本語名のフルネームを入力してください:"); | |
scanf("%s",&name); | |
printf("アルファベットをどれだけずらすか指定してください:"); | |
scanf("%d",&alpDiff); | |
for (i=0; i<=99; i++) | |
{ | |
isValid = charValid(name[i]); | |
if (isValid == 0) | |
{ | |
name2[i] = charAddition(name[i],alpDiff); | |
} | |
else | |
{ | |
name2[i] = name[i]; | |
} | |
} | |
printf("変換後の文字列は %s です。\n",name2); | |
printf("変換した文字列の解析を行います\n"); | |
for (i2=0; i2<26; i2++) | |
{ | |
curVowel = 0; | |
baseAlpha[0] = charAddition('a',i2); | |
baseAlpha[1] = charAddition('i',i2); | |
baseAlpha[2] = charAddition('u',i2); | |
baseAlpha[3] = charAddition('e',i2); | |
baseAlpha[4] = charAddition('o',i2); | |
baseAlpha[5] = NULL; | |
for (i=0; i<=99; i++) | |
{ | |
isValid = charValid(name2[i]); | |
if (isValid == 0) | |
{ | |
cacheChar1 = name2[i]; | |
cRes = charContains(cacheChar1,baseAlpha); | |
if (cRes == 0) | |
{ | |
curVowel += 1; | |
} | |
} | |
} | |
dict[i2] = curVowel; | |
} | |
for (i=0; i<26; i++) | |
{ | |
if (maxVowelCount < dict[i]) | |
{ | |
maxVowelCount = dict[i]; | |
} | |
} | |
printf("復元後の文字列の候補は\n"); | |
for (i2=0; i2<26; i2++) | |
{ | |
if (maxVowelCount == dict[i2]) | |
{ | |
for (i=0; i<=99; i++) | |
{ | |
isValid = charValid(name[i]); | |
if (isValid == 0) | |
{ | |
name3[i] = charAddition(name2[i],i2); | |
} | |
else | |
{ | |
name3[i] = name2[i]; | |
} | |
} | |
cRes = charContains(charAddition('q',i2),name3); | |
if (cRes == -1) | |
{ | |
cRes = charContains(charAddition('x',i2),name3); | |
if (cRes == -1) | |
{ | |
cRes = charContains(charAddition('l',i2),name3); | |
if (cRes == -1) | |
{ | |
printf("%s\n",name3); | |
} | |
} | |
} | |
} | |
} | |
printf("です\n"); | |
} | |
// return char code + arguments value | |
char charAddition(char ref, int num) | |
{ | |
char ref2 ; | |
int i; | |
ref2 = tolower(ref); | |
i = (int)ref2 + num; | |
while ((i - (int)'a') >= 26) | |
{ | |
i -= 26; | |
} | |
while ((i - (int)'a') < 0) | |
{ | |
i += 26; | |
} | |
return (char)i; | |
} | |
// check char is [a-z] | |
int charValid(char ref) | |
{ | |
char ref2 ; | |
int i; | |
ref2 = tolower(ref); | |
i = (int)ref2; | |
if ((i < (int)'a') || (i > (int)'z')) | |
{ | |
return -1; | |
} | |
return 0; | |
} | |
// represents char[].contains function | |
int charContains(char tag,char ref[]) | |
{ | |
char *p; | |
p = strchr(ref,tag); | |
if (p != NULL) | |
{ | |
return 0; | |
} | |
else | |
{ | |
return -1; | |
} | |
} | |
/* | |
int charCheck(char ref) | |
{ | |
char ref2 ; | |
ref2 = tolower(ref); | |
switch (ref) | |
{ | |
case 'q' : | |
case 'x' : | |
case 'l' : | |
case 'v' : | |
return -1; | |
break; | |
case 'a' : | |
case 'i' : | |
case 'u' : | |
case 'e' : | |
case 'o' : | |
return 1; | |
break; | |
case 'w' : | |
return 32; | |
break; | |
} | |
} | |
int charNextable(int mode,char ref,char next) | |
{ | |
char ref2 ; | |
char ref3 ; | |
ref3 = tolower(next); | |
ref2 = tolower(ref); | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment