彩券號碼,開獎號碼不會重複
可以Get字串再轉成int進行比對
無法直接輸入int 因為,前面的空格是隨機給的
#include<stdbool.h>
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
int n = 0;
int input[5] = { 0 };
char a[100] = { '\0' }, b[100] = { '\0' };
int ans[5] = { 0 }, count = 0;
scanf("%d", &n);
getchar();
while (n)
{
gets_s(a);
gets_s(b);
int j = 0;
for (int i = 0; i < strlen(a); i++)
{
if (a[i] == ',' || a[i] == ' ')
{
continue;
}
else if (a[i + 1] >= '0' && a[i + 1] <= '9')
{
input[j] = 10 * (a[i] - '0') + (a[i + 1] - '0');
j++;
}
}
j = 0;
for (int i = 0; i < strlen(b); i++)
{
if (b[i] == ',' || b[i] == ' ')
{
continue;
}
else if (b[i + 1] >= '0' && b[i + 1] <= '9')
{
ans[j] = 10 * (b[i] - '0') + (b[i + 1] - '0');
j++;
}
}
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
if (input[i] == ans[j])
{
count++;
}
}
}
printf("%d\n", count);
count = 0;
n--;
memset(a, '\0', sizeof(a));
memset(b, '\0', sizeof(b));
}
return 0;
}