Skip to content

Instantly share code, notes, and snippets.

@m-hayabusa
Created December 19, 2017 02:37
Show Gist options
  • Save m-hayabusa/b1b46946db52dc11f128b02f24e844b8 to your computer and use it in GitHub Desktop.
Save m-hayabusa/b1b46946db52dc11f128b02f24e844b8 to your computer and use it in GitHub Desktop.
numer0n.c
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define DEBUG
int randnum_seed = 0;
int randnum(int start, int end){
randnum_seed = randnum_seed + 1;
srand(time(NULL)+randnum_seed);
return(rand()%(end-start) + start);
}
int a[3] = {};
int b[3] = {};
int setup() {
for(int i = 0; i <= 2; i++){
a[i] = randnum(0,9);
if(i==2){
while(a[0]==a[2] || a[1]==a[2]){
a[i] = randnum(0,9);
}
}
#ifdef DEBUG
printf("%d ", a[i]);
#endif
}
#ifdef DEBUG
printf("\n");
#endif
}
int main() {
setup();
while (1){
printf("スペースで区切って数字を3つ入力: ");
scanf("%d %d %d",&b[0],&b[1],&b[2]);
#ifdef DEBUG
printf("%d %d %d\n",b[0],b[1],b[2]);
#endif
int s = (a[0] == b[0]) + (a[1] == b[1]) + (a[2] == b[2]);
if (s == 3) {
printf("Yeah!\n");
break;
} else {
printf("mm...\n");
if (s != 0) {
printf("%dつあっています\n",s);
}
}
// if(a[0] == b[0] && a[1] == b[1] && a[2] == b[2]) {
// printf("Yeah!\n");
// break;
// } else {
// printf("mm...\n");
// }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment