[ACM ] 102 WA(已解決) (附帶請問cin 和 scanf的問題)
剛剛改了一下結果就AC了
我想請問C/C++高手一個問題
就是cin scanf 實質上的差別或是概念上有什麼不同
cin是不是可能會讀到空白之類的
我把程式本來cin的部分換成scanf結果就過了
所以想請問一下大家(我修改過的用紅色標起來)
謝謝大家
作者: rock1985 (疾風) 看板: C_and_CPP
標題: [ACM ] 102 WA
時間: Mon Jul 12 21:21:58 2010
( *[1m *[m 為色碼,可以按 Ctrl+V 預覽會顯示的顏色 )
( 未必需要依照此格式,文章條理清楚即可 )
題號: 102
遇到的問題: WA
有問題的code: (請善用置底文的標色功能)
#include <iostream>
#include<stdio.h>
#include<cstdio>
using namespace std;
string funct(int c1 , int c2 , int c3 , string s_temp , int temp , int
temp_max);
/*******************************/
/* glass[a][b] */
/* a is bucket number */
/* b is glass color */
/* b = 1 Brown */
/* b = 2 Green */
/* b = 3 Clean */
/*******************************/
int main(int argc, char* argv[])
{
unsigned int Bucket[3][3];
int can_1, can_2, can_3;
while(cin != NULL) (改這行換scnf)
while (scanf("%d %d %d %d %d %d %d %d %d", &Bucket[0][0],
&Bucket[0][1],&Bucket[0][2],&Bucket[1][0],&Bucket[1][1],&Bucket[1][2],
&Bucket[2][0],&Bucket[2][1],&Bucket[2][2])!= EOF)
{
/* initiate */
unsigned int max = 0 , move = 0;
unsigned int init = 0, total = 0, temp_total = 0;
string s_goal = "XXX";
for(int i=0 ; i<3 ; i++)
{
for(int j=0 ; j<3 ; j++)
{
//cin>>Bucket[i][j]; (本行刪掉)
total = total + Bucket[i][j];
}
}
for(can_1=0 ; can_1<3 ; can_1++)
{
init = Bucket[0][can_1];
temp_total = Bucket[0][can_1];
for(can_2=0 ; can_2<3 ; can_2++)
{
if(can_1 != can_2)
{
temp_total = temp_total + Bucket[1][can_2];
for(can_3=0 ; can_3<3 ; can_3++)
{
if( (can_3 != can_2) && (can_3 != can_1) )
{
temp_total = temp_total + Bucket[2][can_3];
//cout<<temp_total<<endl;
if(temp_total >= max)
{
s_goal = funct(can_1 , can_2 , can_3 , s_goal
, temp_total , max);
max = temp_total;
}
temp_total = init;
}
}
}
//temp_total = init;
}
}
move = total - max;
cout<< s_goal << " " << move <<endl;
}
return 0;
}
string funct(int c1 , int c2 , int c3 , string s_temp , int temp , int
temp_max)
{
string str="";
int size = 0;
if(c1==0){
str=str+"B";
}else if(c1==1){
str=str+"G";
}else str=str+"C";
if(c2==0){
str=str+"B";
}else if(c2==1){
str=str+"G";
}else str=str+"C";
if(c3==0){
str=str+"B";
}else if(c3==1){
str=str+"G";
}else str=str+"C";
if(temp == temp_max)
{
while(size < 2)
{
if(str[size] < s_temp[size])
return str;
else if(str[size] > s_temp[size])
break;
else
size++;
}
return s_temp;
}
return str;
}
補充說明:
本來想用6種case去討論
但是想說換個寫法,結果就快樂的WA了
請大家幫我看看是哪裡出問題了 謝謝
--
我不是宅 我只是比較居家
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 111.248.15.120
推
07/12 21:56, , 1F
07/12 21:56, 1F
推
07/12 22:49, , 2F
07/12 22:49, 2F
→
07/12 22:49, , 3F
07/12 22:49, 3F
→
07/12 22:50, , 4F
07/12 22:50, 4F
→
07/12 22:51, , 5F
07/12 22:51, 5F
※ 編輯: rock1985 來自: 111.248.15.120 (07/12 23:08)
※ 編輯: rock1985 來自: 111.248.15.120 (07/12 23:10)
推
07/12 23:28, , 6F
07/12 23:28, 6F
→
07/12 23:29, , 7F
07/12 23:29, 7F
→
07/12 23:29, , 8F
07/12 23:29, 8F
推
07/12 23:35, , 9F
07/12 23:35, 9F
→
07/12 23:36, , 10F
07/12 23:36, 10F
→
07/12 23:36, , 11F
07/12 23:36, 11F
→
07/12 23:37, , 12F
07/12 23:37, 12F
推
07/13 00:56, , 13F
07/13 00:56, 13F
推
07/13 01:00, , 14F
07/13 01:00, 14F
→
07/13 01:00, , 15F
07/13 01:00, 15F
→
07/13 01:01, , 16F
07/13 01:01, 16F
→
07/13 01:05, , 17F
07/13 01:05, 17F
推
07/13 01:06, , 18F
07/13 01:06, 18F
→
07/13 03:36, , 19F
07/13 03:36, 19F
→
07/13 03:41, , 20F
07/13 03:41, 20F
→
07/13 19:03, , 21F
07/13 19:03, 21F
→
07/13 19:04, , 22F
07/13 19:04, 22F
推
07/13 19:07, , 23F
07/13 19:07, 23F
→
07/13 19:08, , 24F
07/13 19:08, 24F
→
07/13 19:08, , 25F
07/13 19:08, 25F
→
07/13 19:08, , 26F
07/13 19:08, 26F
→
07/13 19:09, , 27F
07/13 19:09, 27F
→
07/13 19:09, , 28F
07/13 19:09, 28F
→
07/13 19:10, , 29F
07/13 19:10, 29F
→
07/13 19:11, , 30F
07/13 19:11, 30F
→
07/13 19:12, , 31F
07/13 19:12, 31F
→
07/13 19:13, , 32F
07/13 19:13, 32F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章