2018年7月23日 星期一

itsa [C_AR16-易]統一發票對獎

#include<iostream>
#include<string>
using namespace std;

int main()
{
int N,count,tmp;
long int sum;
int arr[7] = {0};
int mon[7] = {2000000,200000,40000,10000,4000,1000,200};
string t, h1, h2, h3, num;
getline(cin, t);
getline(cin, h1);
getline(cin, h2);
getline(cin, h3);
sum = 0;
cin >> N;
cin.ignore();
for (int i = 0; i < N; i++)
{
tmp = 0;
count = 0;
getline(cin, num);
if (num == t)
{
arr[0]++;
}
else
{
for (int j = 0; j < 3; j++)
{
if (j == 0)
{
for (int a = 7; a >= 0; a--)
{
if (num[a] == h1[a])
count++;
else
break;
}
if (count >= 3)
tmp = count;
count = 0;
}
else if (j == 1)
{
for (int a = 7; a >= 0; a--)
{
if (num[a] == h2[a])
count++;
else
break;
}
if (count >= 3)
if (count > tmp)
tmp = count;
count = 0;
}
else if (j == 2)
{
for (int a = 7; a >= 0; a--)
{
if (num[a] == h3[a])
count++;
else
break;
}
if (count >= 3)
if (count > tmp)
tmp = count;
arr[9 - tmp]++;
count = 0;
}
}
}
}
for (int c = 0; c < 7; c++)
{
sum += mon[c] * arr[c];
}
for (int k = 0;k < 7; k++)
{
cout << arr[k];
if (k < 6)
cout << " ";
}
cout << endl;
cout << sum << endl;
return 0;
}

沒有留言:

張貼留言