主题:acm Flat
#include<stdio.h>
#include <string.h>
#define N 10
struct {
int s;
char name[N];
}room[N];
void main()
{
int n;
float p,sum1=0;int sum2=0,sum=0;
scanf("%d %f",&n,&p);
for(int i=0;i<n;i++)
scanf("%d %s",&room[i].s,room[i].name);
for(i=0;i<n;i++)
sum+=room[i].s;
printf("%d\n",sum);
sum1=(float)sum;
for( i=0;i<n;i++)
{
if(strcmp("balcony",room[i].name)==0)
sum1=sum1-(float)room[i].s/2;
if(strcmp("bedroom",room[i].name)==0)
sum2=sum2+room[i].s;
}
printf("%d\n",sum2);
printf("%.1f",sum1*p);
}
ACM ICPC 2011–2012, NEERC, Northern Subregional Contest
St Petersburg, October 29, 2011
Problem F. Flat
Input file: flat.in
Output file: flat.out
Time limit: 3 seconds
Memory limit: 256 megabytes
You are one of the developers of software for a real estate agency. One of the functions you are to
implement is calculating different kinds of statistics for flats the agency is selling. Each flat consists of
different types of rooms: bedroom, bathroom, kitchen, balcony and others.
The cost of the flat is equal to the product of reduced total area and the cost of one square metre.
Reduced total area is the total area of all rooms except for balconies plus one half of balconies total area.
You will be given some information about the area of each room in the flat and the cost of one square
metre. You are to calculate the following values for the flat:
the total area of all rooms;
the total area of all bedrooms;
the cost of the flat.
Input
The first line of the input file contains two integer numbers n (1 n 10) and c (1 c 100 000) —
number of rooms in the flat and the cost of one square metre, respectively.
Each of the following n lines contains an integer number ai (1 ai 100) and a word ti — the area of
i-th room and its type, respectively. Word ti is one of the following: “bedroom”, “bathroom”, “kitchen”,
“balcony”, “other”.
Output
The first line of the output file should contain one integer number — the total area of all rooms of the
flat. The second line of the output file should contain one integer number — the total area of bedrooms
of the flat. The third line of the output file should contain one real number — the cost of the flat with
precision not worse than 10−6 .
Examples
flat.in flat.out
6 75000 46
8 other 16
3 bathroom 3187500
2 bathroom
10 kitchen
16 bedroom
7 balcony
2 75123 25
10 kitchen 0
15 balcony 1314652.5
The figure shows the flat from the first example.
求解释错在哪里,为什么提交的时候是编译错误
#include <string.h>
#define N 10
struct {
int s;
char name[N];
}room[N];
void main()
{
int n;
float p,sum1=0;int sum2=0,sum=0;
scanf("%d %f",&n,&p);
for(int i=0;i<n;i++)
scanf("%d %s",&room[i].s,room[i].name);
for(i=0;i<n;i++)
sum+=room[i].s;
printf("%d\n",sum);
sum1=(float)sum;
for( i=0;i<n;i++)
{
if(strcmp("balcony",room[i].name)==0)
sum1=sum1-(float)room[i].s/2;
if(strcmp("bedroom",room[i].name)==0)
sum2=sum2+room[i].s;
}
printf("%d\n",sum2);
printf("%.1f",sum1*p);
}
ACM ICPC 2011–2012, NEERC, Northern Subregional Contest
St Petersburg, October 29, 2011
Problem F. Flat
Input file: flat.in
Output file: flat.out
Time limit: 3 seconds
Memory limit: 256 megabytes
You are one of the developers of software for a real estate agency. One of the functions you are to
implement is calculating different kinds of statistics for flats the agency is selling. Each flat consists of
different types of rooms: bedroom, bathroom, kitchen, balcony and others.
The cost of the flat is equal to the product of reduced total area and the cost of one square metre.
Reduced total area is the total area of all rooms except for balconies plus one half of balconies total area.
You will be given some information about the area of each room in the flat and the cost of one square
metre. You are to calculate the following values for the flat:
the total area of all rooms;
the total area of all bedrooms;
the cost of the flat.
Input
The first line of the input file contains two integer numbers n (1 n 10) and c (1 c 100 000) —
number of rooms in the flat and the cost of one square metre, respectively.
Each of the following n lines contains an integer number ai (1 ai 100) and a word ti — the area of
i-th room and its type, respectively. Word ti is one of the following: “bedroom”, “bathroom”, “kitchen”,
“balcony”, “other”.
Output
The first line of the output file should contain one integer number — the total area of all rooms of the
flat. The second line of the output file should contain one integer number — the total area of bedrooms
of the flat. The third line of the output file should contain one real number — the cost of the flat with
precision not worse than 10−6 .
Examples
flat.in flat.out
6 75000 46
8 other 16
3 bathroom 3187500
2 bathroom
10 kitchen
16 bedroom
7 balcony
2 75123 25
10 kitchen 0
15 balcony 1314652.5
The figure shows the flat from the first example.
求解释错在哪里,为什么提交的时候是编译错误