Pages

Saturday, July 30, 2011

a059. 完全平方和


#include
#include
using namespace std;

int main()
{
int n;
cin>>n;
for(int group=0;group {
cout<<"Case "< int a,b,sum=0;
cin>>a>>b;
for(int num=a;num<=b;num++)
{
if( (sqrt(num)*sqrt(num)) == num)
sum += num;
}
cout< }

return 0;
}

a148. You Cannot Pass?!


#include

using namespace std;

int main()
{
int num;
while(cin>>num)
{
double sum=0,avg;
for(int i=0;i {
int score;
cin>>score;
sum += score;
}
avg = sum / num;
cout<<((avg>59)? "no":"yes")< }
return 0;
}

d072: 文文的求婚--續集 (Case 版)


#include

using namespace std;

int main()
{
int num;
cin>>num;
for(int i=0;i {
cout<<"Case "< int year;
cin>>year;
if((year%4==0 && year%100!=0) || year%400==0)
cout<<"a leap year"< else cout<<"a normal year"< }
return 0;
}

d071. 文文的求婚--續集 (EOF 版)


#include

using namespace std;

int main()
{
int year;
while(cin>>year)
{
if(cin.eof()) break;
if((year%4==0 && year%100!=0) || year%400==0)
cout<<"a leap year"< else cout<<"a normal year"< }
return 0;
}

d070. 文文的求婚--續集 (0 尾版)


#include

using namespace std;

int main()
{
int year;
while(cin>>year)
{
if(!year) break;
if((year%4==0 && year%100!=0) || year%400==0)
cout<<"a leap year"< else cout<<"a normal year"< }
return 0;
}

d074. 電腦教室


#include
using namespace std;

int main() {
int num,max=0;
cin>>num;
for(int i=0;i {
int people;
cin>>people;
if(people>max) max=people;
}
cout< return 0;
}

d073. 分組報告


#include
using namespace std;

int main() {
int num,ans;
cin>>num;
ans = ((num-1)/3+1);
cout< return 0;
}

d068. 該減肥了!


#include
using namespace std;

int main() {
int weight;
cin>>weight;
cout<< ((weight>50)? weight-1:weight);
return 0;
}

d069: 文文的求婚--續集 (n 行版)


#include
using namespace std;

int main() {
int num,y;
cin>>num;
for(int i=0;i {
cin>>y;
if( (y%4==0 && y%100!=0 )|| y%400==0)
cout<<"a leap year"< else cout<<"a normal year"< }
return 0;
}

d067. 文文的求婚--續集 (1 行版)


#include
using namespace std;

int main() {
int y;
cin>>y;
if( (y%4==0 && y%100!=0 )|| y%400==0)
cout<<"a leap year";
else cout<<"a normal year";
return 0;
}

a038. 數字翻轉


#include
using namespace std;

int main() {
string num;
while(cin>>num)
{
int l = num.length();
for(int i=0,flag_meet_value=0;i {
if(flag_meet_value==0 && num[l-1-i]=='0') continue;
else flag_meet_value=1;
if(flag_meet_value==1) cout< }
cout< }
return 0;
}

Friday, July 29, 2011

a044. 空間切割


#include
using namespace std;

int cut(int n)
{
if(n==1) return 2;
else return cut(n-1)+((n*n-n+2)/2);
}

int main(void)
{
int n;
while(cin>>n){
cout << cut(n) << endl ;
}
return 0;
}

a053. Sagit's 計分程式


#include

using namespace std;

int main()
{
int num;
while(cin>>num)
{
if(num<=10) cout< else if(num<=20) cout<<(num-10)*2+60< else if(num<=40) cout<<(num-20)*1+80< else cout<<100< }
return 0;
}

a149. 乘乘樂


#include

using namespace std;

int main()
{
int num;
cin>>num;
for(int i=0;i {
int integer;
int mul,mul_sum=1;
cin>>integer;
while(integer%10!=0)
{
mul = integer%10;
mul_sum *= mul;
integer /= 10;
}
cout<
}
return 0;
}

a042. 平面圓形切割


#include
using namespace std;

int main(){
int n;
while (cin >> n)
{
cout << n*n-n+2 << endl;
}
return 0;
}

a121. 質數又來囉


#include
using namespace std;
#include

int main()
{
int a,b;
while(cin>>a>>b)
{
int prime_num=0;
for(int num=a;num<=b;num++)
{
if (num==1) continue;
else if(num==2){ prime_num++;continue;}
else if(num==3) { prime_num++;continue;}
else
{
int flag_isprime=1;
for(int factor=2;factor<=sqrt(num)+1;factor++)
if(num%factor==0){flag_isprime=0;break;}
if (flag_isprime==1)
prime_num++;
}
}
cout< }
return 0;
}

a147: Print it all


#include
using namespace std;

int main()
{
int num;
while(cin>>num)
{
for(int i=1;i {
if(i%7==0) continue;
cout< }
cout< }
return 0;
}

d498 我不說髒話


#include
using namespace std;

int main()
{
int times;
cin>>times;
for(int i=0;i cout<<"I don't say swear words!"< return 0;
}

d485: 我愛偶數


#include
using namespace std;

int main()
{
int a,b,evens_num;
cin>>a>>b;
evens_num = abs(a-b)/2;
if(a%2==0 || b%2==0)
evens_num++;
cout< return 0;
}

d050. 妳那裡現在幾點了?


#include
using namespace std;

int main()
{
int tw_time,us_time;
cin >> tw_time;
us_time = (tw_time + 24 -15 )%24;
cout << us_time << endl;
return 0;
}

d049: 中華民國萬歲!


#include
using namespace std;

int main()
{
int year;
cin >> year;
cout<< year - 1911 < return 0;
}

d058: BASIC 的 SGN 函數


#include
#include
using namespace std;

int main()
{
int t;
while(cin >> t)
{
cout<<( t > 0 ? 1 : (t < 0 ? -1 : 0) );
}
return 0;
}

d051 糟糕,我發燒了!


//參考網頁 http://www.wretch.cc/blog/mntkey/21031128

#include
#include
using namespace std;

int main()
{
double F;
double C;
cin >> F;
C = ( F - 32 ) * 5 / 9;
cout << fixed << setprecision(3) << C << endl;
return 0;
}

d010: 盈數、虧數和完全數


#include
using namespace std;
#include
#define ATSCHOOL_MINUTES 450 //60*7+30=450
#define OFFSCHOOL_MINUTES 1020 //60*17+0=1020

int main()
{
int num;
while(cin>>num)
{
int factors_sum=0;
for(int factor=1;factor {
if(num % factor == 0)
{
factors_sum += factor;
}
}
if(factors_sum cout<<"虧數"< else if(factors_sum>num)
cout<<"盈數"< else
cout<<"完全數"< }
return 0;
}

d060: 還要等多久啊?


#include
using namespace std;

int main() {
int m ;
while(cin >> m)
{
cout << (85-m) % 60 << endl ;
}
return 0;
}

d066 上學去吧!


#include
using namespace std;
#include
#define ATSCHOOL_MINUTES 450 //60*7+30=450
#define OFFSCHOOL_MINUTES 1020 //60*17+0=1020

int main()
{
int hour,minute,time,atschoolMinute,OFFSCHOOL;
cin>>hour>>minute;
time = hour*60 + minute;
cout<< ( (ATSCHOOL_MINUTES<=time && time
return 0;
}

d065 三人行必有我師


#include
#include

using namespace std;

int main(int argc, char *argv[])
{
int a,b,c,biggerNum;
while(cin>>a>>b>>c)
{
biggerNum = max(a,b);
biggerNum = max(biggerNum,c);
cout< }
return 0;
}

d064. ㄑㄧˊ 數?


#include

using namespace std;

int main(int argc, char *argv[])
{
int input;
while(cin>>input)
{
cout<< ((input%2==0)? "Even":"Odd")<

}
return EXIT_SUCCESS;
}

d063: 0 與 1


#include

using namespace std;

int main(int argc, char *argv[])
{
int input;
while(cin>>input)
{
cout< }

return EXIT_SUCCESS;
}

Wednesday, July 27, 2011

a011. 幼稚園的算數遊戲


/*
程式碼長度: 606 Bytes
執行檔大小: 10341 Bytes
*/

#include
using namespace std;
#include

int main()
{
string str1;
int n=0;
int firstch=1;
while(getline(cin,str1))
{
for(int i=0; i<=str1.length(); i++)
{
if(isalpha(str1[i])!=0)
{
if(firstch==1)
{
n++;
}
firstch=0;
}
else
{
firstch=1;
}
}
cout< n=0;
}

system("pause");
return 0;
}

a010. 因數分解


/*
程式碼長度: 1538 Bytes
執行檔大小: 9121 Bytes
*/

#include
using namespace std;
#include

int main()
{
int input;
int p_input;
int pow=0;
int firstdigit=1;
int dividable=0;
while(cin>>input)
{
p_input=input;
for(int i=2;i<= p_input;i++)
{
while(p_input%i==0)
{
dividable=1;
pow++;
p_input = p_input/i;
}

if(dividable==1)
{
if(firstdigit==0)
{
cout<<" * ";
}
else
{
firstdigit=0;
}


if(pow==1)
{
cout< }
else if(pow>1)
{
cout<< i<<"^"< }
dividable=0;
pow=0;

}
}
firstdigit=1;
cout< }


return 0;
}

Tuesday, July 26, 2011

a012: Hashmat的戰役


#include
using namespace std;

int main()
{
long long x, y;
while( cin >> x >> y )
cout << abs( x-y ) << endl;
return 0;
}

a008: 中文大寫數字


#include
using namespace std;
#include

int main( void )
{
string number[15] = { "零", "壹", "貳", "參", "肆", "伍", "陸", "柒", "捌", "玖" };
string value[15] = { "", "拾", "佰", "仟", "萬", "拾", "佰", "仟", "億", "拾", "佰"};

int num;
while( cin >> num )
{
int num_divide[15] = {0};
int value_no = 0;
int max_value = 0;

for(value_no=0;num>0;value_no++)
{
num_divide[value_no] = num % 10;
num /= 10;
}
max_value = value_no-1;

for( int i = max_value ; i >= 0 ; i-- )
{
if( num_divide[i] != 0 )
cout << number[num_divide[i]] << value[i];
else if( i == 4 || i == 8 )
cout << value[i];
else if( i==0 )
cout<<"";
else if( num_divide[i-1] != 0 )
cout << number[num_divide[i]];
}
cout << endl;
}
return 0;
}

Monday, July 25, 2011

a007. 判斷質數


#include
#include
using namespace std;

int main()
{
int input;
while( cin >> input )
{
if( input == 2 )
cout<<"質數"< else if( input % 2 == 0 )
cout<<"非質數"< else
{
int isPrime = 1;
for( int i = 3 ; i <= sqrt((double)input); i++ )
{
if( input % i == 0 )
{
cout<<"非質數"< isPrime = 0;
break;
}
}
if( isPrime )
cout<<"質數"< }
}

return 0;
}

a006. 一元二次方程式


#include
#include
using namespace std;

int main()
{
int a, b, c;
while( cin >> a >> b >> c )
{
int sqrtOfThis=sqrt((double)(b*b-4*a*c));
if( b*b - 4*a*c < 0 )
cout << "No real root\n";
else if( b*b - 4*a*c == 0 )
cout << "Two same roots x=" << -b/(2*a) << endl;
else
cout << "Two different roots x1=" << (-b + sqrtOfThis ) / (2*a)
<< " , x2=" << (-b - sqrtOfThis) / (2*a) << endl;
}
return 0;
}

a005. Eva 的回家作業


#include
using namespace std;

int main() {
double number , i1 , i2 , i3 , i4 ,i5 ;
while(cin >> number)
{
while(cin >> i1 >> i2 >> i3 >> i4 )
{
if((i2 - i1) == (i4 - i3))
{
i5 = i4 + (i4 - i3) ;
}
else
{
i5 = i4 * (i2/i1);
}
cout << i1 << " " << i2 << " " << i3 << " " << i4 << " " << i5 << endl ;
}
}
return 0;
}

a004: 文文的求婚


#include
using namespace std;

int main()
{
int year;
while( cin >> year )
{
if( ( year % 4 == 0 && year % 100 != 0 ) || (year % 400 == 0) )
cout << "閏年\n";
else
cout << "平年\n";
}
return 0;
}

a003: 兩光法師占卜術


#include
using namespace std;

int main()
{
int M,D,S;
while(cin>>M>>D)
{
S=(M*2+D)%3;
if(S==0)
{
cout<<"普通"< }
else if(S==1)
{
cout<<"吉"< }
else if(S==2)
{
cout<<"大吉"< }
}

return 0;
}

a002: 簡易加法


#include
using namespace std;

int main()
{
int i, j;
while( cin >> i >> j )
cout << i+j << endl;
return 0;
}

a001: 哈囉

 
#include
using namespace std;
int main() {
string s;
while(cin >> s){
cout << "hello, "<< s << endl;
}
return 0;
}

Wednesday, July 20, 2011

使用 SyntaxHighlighter

使用 SyntaxHighlighter

"儲存之後,張貼程式碼只要使用 這樣的語法將程式碼框住就可以了。"




.

Monday, July 18, 2011

a016. 數獨(SUDOKU) 尚未成功解出

 

// string::rbegin and string::rend
#include
#include
using namespace std;

void clear(int X[]);
void show(int X[]);
int check(int X[]);
void read(int X[9][9]);
int row_check(int X[9][9]);
int column_check(int X[9][9]);
int square_check(int X[9][9]);

int main ()
{
int A[9][9]={0};
int flag=1;

read(A);
//cout< flag = row_check(A) & flag;
flag = column_check(A) & flag;
flag = square_check(A) & flag;
if(flag) cout<<"yes"< else cout<<"no"< //system("pause");
return 0;
}

void show(int X[])
{
for(int i=0;i<9;i++)
{
cout< }
}
void clear(int X[])
{
for(int i=0;i<10;i++)
{
X[i]=0;
}
}
int check(int X[])
{
int R[10]={0};
int isOk=1;

for(int i=0; i<9; i++)
{
if(R[ X[i] ] ==0)
{
R[ X[i] ]=1;
}
else isOk=0;
}
return isOk;
}
void read(int X[9][9])
{
for(int i=0;i<9;i++)
{
for(int j=0;j<9;j++)
{
cin>>X[i][j];
}
}
}
int row_check(int X[9][9])
{
int flag=1;
int W[9]={0};
for(int i=0;i<9;i++)
{
for(int j=0;j<9;j++)
{
W[i]=X[i][j];
}
if(check(W)==0)
{
flag=0;
}
}
return flag;
}
int column_check(int X[9][9])
{
int flag=1;
int W[9]={0};
for(int j=0;j<9;j++)
{
for(int i=0;i<9;i++)
{
W[i]=X[i][j];
}
if(check(W)==0)
{
flag=0;
}
}
return flag;
}
int square_check(int X[9][9])
{
int flag=1;
int W[9]={0};
int count=0;
for(int i=0;i<9;i+3)
{
for(int j=0;j<9;j+3)
{
for(int i2=0;i2<3;i2++)
{
for(int j2=0;j2<3;j2++)
{
W[count]=X[i+i2][j+j2];
count++;
}
}

if(check(W)==0)
{
flag=0;
}
count=0;
}
}


return flag;
}