本文最后更新于 1170 天前,其中的信息可能已经有所发展或是发生改变。
代码语言:javascript复制// ZOJ-1405Tanning Salon.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
#include<string>
#include<string.h>
using namespace std;
int main()
{
int n;
cin >> n;
while (n!=0)
{
string str;
int sum=1;
int max=0;
cin>>str;
int len = str.length();
char *ch = new char[len];
strcpy(ch, str.c_str());
char *ch1=new char[n];
ch1[0] = ch[0];
for (int k = 1; k < n; k )
{
ch1[k] = '0';
}
for (int i = 1; i < len; i )
{
sum ;
int j;
for ( j= 0; j < n; j )
{
if (ch[i] == ch1[j])
{
sum = sum - 2;
ch1[j] = '0';
break;
}
}
if (j<n)
continue;
if (sum>n)
{
for (j = 0; j < i; j )
{
if (ch[i] == ch[j])
{
max--;
break;
}
}
sum = n;
max ;
}
else
{
for (j = 0; j<n; j )
{
if (ch1[j] == '0')
{
ch1[j] = ch[i];
break;
}
}
}
}
if (max>0)
{
cout << max << " customer(s) walked away." << endl;
}
else
{
cout << "All customers tanned successfully." << endl;
}
cin >> n;
}
return 0;
}
Post Views: 141