Sunday, October 2, 2011
Saturday, October 1, 2011
Tuesday, August 30, 2011
Monday, August 29, 2011
Monday, August 15, 2011
d018. 字串讀取練習
#include
#include
#include
using namespace std;
const int SIZE = 3000;
int main()
{
char input[SIZE];
while(cin.getline(input,SIZE))
{
double sum=0;
char* pch;
pch = strtok(input," :");
while(pch !=NULL)
{
bool IsOdd;
if((int)atoi(pch)%2==1)
IsOdd=1;
else IsOdd=0;
pch = strtok(NULL," :");
if(IsOdd)
sum += atof(pch);
else
sum -= atof(pch);
pch = strtok(NULL," :");
}
cout<}
return 0;
}
Sunday, August 14, 2011
d098: Stringstream運用練習(C++)
#include
#include
#include
using namespace std;
bool IsAllInt(string str);
int main()
{
string input;
while(getline(cin,input))
{
int sum=0;
stringstream stream(input);
while(stream)
{
string word;
stream>>word;
if(IsAllInt(word))
{
sum += atoi(word.c_str());
}
}
cout<}
return 0;
}
bool IsAllInt(string str)
{
for(int i=0;i{
if(!isdigit(str[i]))
return 0;
}
return 1;
}
d583. 幼稚的企鵝
#include
using namespace std;
int main()
{
int n;
while(cin >> n)
{
for(int i=1; i<=n; i++)
{
int temp;
cin >> temp;
cout << i << " ";
}
cout << endl;
}
}
Saturday, August 13, 2011
d635. 幸運777?luck
#include
using namespace std;
int main() {
int input;
while(cin>>input)
{
if(input<0)
{
cout<<"-1"<break;
}
cout<}
return 0;
}
d649. 數字三角形
#include
#include
#include//格式控制
#include
using namespace std;
int main() {
int input;
while(cin>>input)
{
string str;
for(int i=1;i<=input;i++)
{
str +='+';
cout.setf(ios::right);
cout << setw(input) << setfill('_') << str<}
cout<}
return 0;
}
d059. 數學函數練習
#include
#include
#include//格式控制
using namespace std;
int main() {
double a,b;
cin>>a>>b;
cout << pow(a,b) << endl ; //a 的 b 次方
double c;
cin>>c;
cout << fixed << setprecision(3) << sqrt(c) << endl ;
int d;
cin>>d;
cout<
int e,f;
cin>>e>>f;
cout<<(rand()%(f-e))+e << endl ;
return 0;
}
d532. 文文的求婚 (三)
#include
using namespace std;
int main()
{
int a,b,count=0;
cin>>a>>b;
for(int year=a;year<=b;year++)
{
if((year%4==0 && year%100!=0) || (year%400==0))
count++;
}
cout<
return 0;
}
d559. 班號
#include
using namespace std;
int main()
{
int input;
while(cin>>input)
{
cout<<"'C' can use printf(\"%d\",n); to show integer like "< }
return 0;
}
d827. 買鉛筆
#include
using namespace std;
int main()
{
int input,dozens,singles,output;
cin>>input;
dozens = input/12;
singles = input%12;
output = dozens*50+singles*5;
cout< return 0;
}
d122. Oh! My Zero!!
#include
using namespace std;
int main()
{
long input;
while(cin>>input)
{
long output = 0;
while(input>4)
{
input/=5;
output +=input;
}
cout< }
return 0;
}
d489. 伏林的三角地
#include
//海龍公式
using namespace std;
int main()
{
int a,b,c;
cin >> a >> b >> c;
long long int ans = (long long int)(a+b+c)*(b+c-a)*(a+c-b)*(a+b-c);
cout << ans/16 << endl;
return 0;
}
Subscribe to:
Posts (Atom)