日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

SDUT2389Ballot evaluation

發布時間:2024/4/14 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SDUT2389Ballot evaluation 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這個題就是有一個精度誤差的問題 其它還好

題目描述
Before the 2009 elections at the European Parliament, Bill and Ted have asked their friends to make guesses about the outcome of the ballot. Now, the results have been published, so Bill and Ted want to check who was right. But checking the results of their many friends would take a very long time, and they need the evaluation to be done by a computer. Since they are not so good at programming, they ask you for help.



輸入
The data provided by Bill and Ted has the following format: The first line consists of the number p of parties followed by the number g of guesses (with 1 ≤ p ≤ 50 and 1 ≤ g ≤ 10000). Then follow p lines, each line consisting of a unique party name of length ≤ 20 (only containing letters a-z, A-Z and digits 0-9) and the achieved vote percentage of this party with one digit after the decimal point. After the parties follow g lines, each consisting of a guess. A guess has the form P1 + P2 + ... + Pk COMP n, where P1 to Pk are party names, COMP is one of the comparison operators <, >, <=, >= or = and n is an integer between 0 and 100, inclusively. Each party name occurs at most once in each guess.



輸出
For each guess, sum up the vote percentages of the parties and compare them with the specified integer n. Then, print a line stating whether the guess was correct. See the sample output for details.



示例輸入
6 5
CDU 30.7
SPD 20.8
Gruene 12.1
FDP 11.0
DIELINKE 7.5
CSU 7.2
FDP > 11
CDU + SPD < 50
SPD + CSU >= 28
FDP + SPD + CDU <= 42
CDU + FDP + SPD + DIELINKE = 70示例輸出
Guess #1 was incorrect.
Guess #2 was incorrect.
Guess #3 was correct.
Guess #4 was incorrect.
Guess #5 was correct. 1 #include<stdio.h>
2 #include<string.h>
3 typedef struct node
4 {
5 double data;
6 char p[25];
7 int flag;
8 }st;
9 const double eps = 1e-6;
10 int cmp(double x)
11 {
12 if(x > eps) return 1;
13 else if(x < -eps) return -1;
14 else return 0;
15 }
16 int judge(char str[],double s,int n)
17 {
18 int k;
19 k = strlen(str);
20 if(k == 1)
21 {
22 switch(str[0])
23 {
24 case '<':if(cmp(s-n)<0)return 1;break;
25 case '>':if(cmp(s-n)>0)return 1;break;
26 case '=':if(cmp(s-n) == 0)return 1;break;
27 }
28 }
29 else
30 {
31 switch(str[0])
32 {
33 case '<':if(cmp(s-n)<=0)return 1;break;
34 case '>':if(cmp(s-n)>=0)return 1;break;
35 }
36 }
37 return 0;
38 }
39 int main()
40 {
41 int t,g,n,i,x,k = 0,j;
42 st a[55];
43 double s;
44 char str[25];
45 scanf("%d %d",&t,&g);
46 for(i = 1 ; i <= t ; i++)
47 scanf("%s %lf",a[i].p,&a[i].data);
48 while(g--)
49 {
50 k++;
51 s = 0;
52 for(j = 1 ; j <= t ; j++)
53 a[j].flag = 0;
54 while(scanf("%s",str)!=NULL)
55 {
56 if(str[0]!='+'&&str[0]!='<'&&str[0]!='>'&&str[0]!='=')
57 {
58 for(i = 1 ; i <= t ; i++)
59 if(a[i].flag==0)
60 {
61 if(strcmp(str,a[i].p) == 0)
62 {
63 s = s+a[i].data;
64 a[i].flag = 1;
65 }
66 }
67 }
68 else
69 if(str[0]!='+')
70 {
71 scanf("%d",&n);
72 x = judge(str,s,n);
73 break;
74 }
75
76 }
77 if(x)
78 printf("Guess #%d was correct.\n",k);
79 else
80 printf("Guess #%d was incorrect.\n",k);
81 }
82 return 0;
83 }



轉載于:https://www.cnblogs.com/shangyu/archive/2012/02/26/2369035.html

總結

以上是生活随笔為你收集整理的SDUT2389Ballot evaluation的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。