時間限制:1 秒 內存限制:32 兆 特殊判題:否 提交:1378 解決:595
http://ac.jobdu.com/problem.php?pid=1166
題目描述:
立方根的逼近迭代方程是 y(n+1) = y(n)*2/3 + x/(3*y(n)*y(n)),其中y0=x.求給定的x經過n次迭代後立方根的值。
輸入:
輸入有多組數據。
每組一行,輸入x n。
輸出:
迭代n次後的立方根,double精度,保留小數點後面六位。
樣例輸入:
3000000 28
樣例輸出:
144.224957
#include<stdio.h>
main()
{
int i, n, x;
double m;
while( scanf("%d%d",&x,&n)==2 ){
for( m=x, i=0;i<n;i++ )
m = m*2/3 + x/(3*m*m);
printf("%.6f\n",m);
}
}
九度OJ 題目1167:數組排序
時間限制:1 秒 內存限制:32 兆 特殊判題:否 提交:2077 解決:645
http://ac.jobdu.com/problem.php?pid=1167
題目描述:
輸入一個數組的值,求出各個值從小到大排序後的次序。
輸入:
輸入有多組數據。
每組輸入的第一個數爲數組的長度n(1<=n<=10000),後面的數爲數組中的值,以空格分割。
輸出:
各輸入的值按從小到大排列的次序(最後一個數字後面沒有空格)。
樣例輸入:
4
-3 75 12 -3
樣例輸出:
1 3 2 1
#include <stdio.h>
#include <algorithm>
struct E{ int d, old, r; }a[10002]; //r=rank
bool CMP(E x, E y){return x.d<y.d;}
bool CMP2(E x, E y){return x.old<y.old;}
int main()
{
int i, j, k, m, n;
freopen("1167.txt","r",stdin);//
while( scanf("%d",&n) == 1 ){
for( i=0; i<n; i++ ){
scanf("%d",&a[i].d);
a[i].old = i;
}
std::sort(a,a+n,CMP);
a[0].r = 1;
for( i=1,j=1; i<n; i++ ){
if(a[i].d==a[i-1].d) a[i].r = j;
else a[i].r = ++j;
}
std::sort(a,a+n,CMP2);
printf("%d",a[0].r);
for( i=1; i<n; i++ )
printf(" %d",a[i].r);
puts("");
}
return 0;
}
九度OJ 題目1168:字符串的查找刪除
時間限制:1 秒 內存限制:32 兆 特殊判題:否 提交:1451 解決:483
http://ac.jobdu.com/problem.php?pid=1168
題目描述:
給定一個短字符串(不含空格),再給定若干字符串,在這些字符串中刪除所含有的短字符串。
輸入:
輸入只有1組數據。
輸入一個短字符串(不含空格),再輸入若干字符串直到文件結束爲止。
輸出:
刪除輸入的短字符串(不區分大小寫)並去掉空格,輸出。
樣例輸入:
in
#include
int main()
{
printf(" Hi ");
}
樣例輸出:
#clude
tma()
{
prtf("Hi");
}
提示:
注:將字符串中的In、IN、iN、in刪除。
#include <fstream>
#include <string>
#include <iostream>
using namespace std;
int main()
{
int i, n, l;
ifstream cin("jobdu_104.txt");//
string s, t;
cin >> s;
l = s.length();
//getchar();
getline(cin,t);
while( getline(cin,t) ){
n = t.find(s);
while( n != -1 ){
t.erase(n,l);
n = t.find(s);
}
n = t.length();
for( i=0; i<n; i++)
if( t[i] != ' ') cout << t[i];
cout << endl;
}
return 0;
}