雖然是一道很水很水的題,但是我感覺(jué)很有必要寫點(diǎn)東西。
這是同學(xué)讓我?guī)退{(diào)的題,大凡人們都不愛(ài)看別人代碼,我也是,以前很少看別人代碼,不同的風(fēng)格,不同的想法,看起來(lái)很讓人糾結(jié),不過(guò)這次徹底讓我轉(zhuǎn)變了思想。
這道題沒(méi)什么值得多說(shuō)的,就是考察對(duì)輸入字符串的處理。同學(xué)雖然有很多細(xì)節(jié)沒(méi)有注意到,但是她的解題思路卻讓我的思路煥然一新,大有醍醐灌頂之感。獨(dú)學(xué)而無(wú)友,孤陋寡聞,說(shuō)的不就是寡人嗎。
以下是本題代碼:


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define LEN 200
int main()
{
int i, j;
char s0[LEN];
char s1[LEN], s2[LEN];
int cost;
int earn = 0;
char c0,c1;
while(1)
{
gets(s0);
if(strcmp(s0, "#") == 0)
break;
if(strcmp(s0,"0") == 0)
{
printf("%d\n", earn);
earn = 0;
continue;
}
sscanf(s0, "%s%s%d%c%c", s1, s2, &cost, &c1, &c0);
if(c0 == 'F')
{
earn += 2 * cost;
}
else if(c0 == 'B')
{
earn += cost + cost / 2;
}
else if(c0 == 'Y')
{
if(cost <= 500)
earn += 500;
else
earn += cost;
}
//
//printf("s0 = %s\n", s0);
//printf("s1 = %s s2 = %s cost = %d c = %c\n", s1, s2, cost, c0);
//
}
//system("pause");
}
posted on 2012-08-09 11:17
小鼠標(biāo) 閱讀(342)
評(píng)論(0) 編輯 收藏 引用 所屬分類:
水題