Public Sub test()
For Each sl In ActivePresentation.Slides
sl.Shapes(1).Top = 40
sl.Shapes(1).Left = 50
sl.Shapes(2).Top = 150
sl.Shapes(2).Left = 50
Next
End Sub
標籤雲
2014年6月18日 星期三
powerpoint VBA -- 自動調整位置
2014年6月17日 星期二
dp - 最大連續元素和
#include <iostream>
using namespace std;
int main()
{
int n;
int a[100];
while (cin>>n)
{
for (int i=0;i<n;i++)
cin >> a[i];
int sMax = 0;
for (int i=0;i<n;i++)
{
int curSum=a[i];
for (int j=i+1;j<n;j++)
{
curSum = curSum + a[j];
if (sMax < curSum)
sMax = curSum;
}
}
cout << sMax<<endl;
}
return 0;
}
2014年6月16日 星期一
動態規劃
#include <cstdlib>
#include <iostream>
using namespace std;
long long int t[100];
long long int f(long long int n)
{
if (t[n]!=0) return t[n];
if (n <=2)
{
t[n] = n;
return t[n];
}
else
{
t[n] = f(n-1)+f(n-2);
return t[n];
}
}
int main()
{
memset(t,0,100*sizeof(t[0]));
long long int n;
while (cin >> n)
cout << f(n) << ' ' << f(f(n)%n) << endl;
}
1000 !
#include <cstdlib>
#include <iostream>
using namespace std;
int a[3000];
int n_to_array(int n)
{
int j=0;
while (n>0)
{
a[j] = n%10;
n = n/10;
j++;
}
}
int array_mul(int n)
{
int c[3000];
memset(c,0,3000*sizeof(c[0]));
for (int i=0;i<3000;i++)
{
if (i==0)
a[i] = a[i] * n;
else
a[i] = a[i] * n+c[i-1];
c[i] = a[i]/10;
a[i] = a[i]%10;
}
}
int out_array(int *a)
{
int i=3000-1;
while (a[i] == 0)
i--;
while (i>=0)
{
cout << a[i];
i--;
}
cout << endl;
}
int main()
{
int n;
while ( cin >> n)
{
memset(a,0,3000*sizeof(a[0]));
a[0]=1;
//n_to_array(1);
for (int i=1;i<=n;i++)
array_mul(i);
out_array(a);
}
//system("PAUSE");
return EXIT_SUCCESS;
}
2014年6月10日 星期二
大數乘法
#include <cstdlib>
#include <iostream>
#include <cstring>
using namespace std;
int mul(int *n1,int *n2,int *n3)
{
for (int i=0;i<100;i++)
{
for (int j=0;j<100;j++)
{
n3[i+j] =n3[i+j]+ n1[j] * n2[i];
if (n3[i+j]>9)
{
n3[i+j+1] =n3[i+j+1]+ n3[i+j]/10;
n3[i+j]=n3[i+j]%10;
}
}
}
}
int toBig(string s,int *n)
{
int x=0;
for (int i=s.length()-1 ;i>=0;i--)
{
n[x]=s[i]-'0';
x++;
}
}
int outResult(int *n)
{
int k=99;
while (n[k]==0)
k--;
for (int i=k;i>=0;i--)
cout << n[i];
cout << endl;
}
int main()
{
string s1,s2;
int n1[100], n2[100], n3[100];
memset(n1,0,100*sizeof(n1[0]));
memset(n2,0,100*sizeof(n1[0]));
memset(n3,0,100*sizeof(n1[0]));
cin >> s1>>s2;
toBig(s1,n1);
toBig(s2,n2);
mul(n1,n2,n3);
outResult(n3);
system("PAUSE");
return EXIT_SUCCESS;
}
大數乘法
#include <cstdlib>
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
string s1,s2;
int n1[100], n2[100], n3[100];
memset(n1,0,100*sizeof(n1[0]));
memset(n2,0,100*sizeof(n1[0]));
memset(n3,0,100*sizeof(n1[0]));
cin >> s1>>s2;
int x=0;
for (int i=s1.length()-1 ;i>=0;i--)
{
n1[x]=s1[i]-'0';
x++;
}
x=0;
for (int i=s2.length()-1 ;i>=0;i--)
{
n2[x]=s2[i]-'0';
x++;
}
for (int i=0;i<100;i++)
{
for (int j=0;j<100;j++)
{
n3[i+j] =n3[i+j]+ n1[j] * n2[i];
if (n3[i+j]>9)
{
n3[i+j+1] =n3[i+j+1]+ n3[i+j]/10;
n3[i+j]=n3[i+j]%10;
}
}
}
int k=99;
while (n3[k]==0)
k--;
for (int i=k;i>=0;i--)
cout << n3[i];
cout << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
大數加法
#include <cstdlib>
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
string s1,s2;
int n1[100], n2[100], n3[100];
memset(n1,0,100*sizeof(n1[0]));
memset(n2,0,100*sizeof(n1[0]));
memset(n3,0,100*sizeof(n1[0]));
cin >> s1>>s2;
int x=0;
for (int i=s1.length()-1 ;i>=0;i--)
{
n1[x]=s1[i]-'0';
x++;
}
x=0;
for (int i=s2.length()-1 ;i>=0;i--)
{
n2[x]=s2[i]-'0';
x++;
}
for (int i=0;i<100;i++)
{
n3[i] =n3[i]+ n2[i] + n1[i];
if (n3[i]>9)
{
n3[i+1] =n3[i+1]+ n3[i]/10;
n3[i]=n3[i]%10;
}
}
int k=99;
while (n3[k]==0)
k--;
for (int i=k;i>=0;i--)
cout << n3[i];
cout << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
stringstream
- #include <iostream>
- #include <string>
- #include <sstream>
- using namespace std;
- int main()
- {
- string line;
- stringstream ss;
- string a;
- bool isFound = false;
- int i = 0;
- int findL;
- int findN;
- while (i<3 )
- {
- getline(cin, line);
- ss.clear();
- ss.str(line);
- int j = 1;
- while (1)
- {
- ss >> a;
- if (ss.fail()) break;
- if (a == "BILL")
- {
- isFound = true;
- findN = j;
- findL = i + 1;
- }
- j++;
- }
- i++;
- }
- if (isFound == true)
- cout << findL << ' ' << findN << endl;
- else
- cout << "NO" << endl;
- return 0;
- }
sstream
- #include <iostream>
- #include <string>
- #include <sstream>
- using namespace std;
- int main()
- {
- string line;
- stringstream ss;
- int sum[3],a;
- for (int i = 0; i < 3; i++)
- {
- getline(cin, line);
- ss.clear();
- ss.str(line);
- sum[i] = 0;
- while (1)
- {
- ss >> a;
- if (ss.fail()) break;
- sum[i] += a;
- }
- //cout << sum[i] << endl;
- }
- int iMax = 0;
- for (int i = 1; i < 3;i++)
- if (sum[i]> sum[iMax])
- iMax = i;
- cout << iMax + 1 << ' '<< sum[iMax] << endl;
- return 0;
- }
2014年6月9日 星期一
cin.getline
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- char line1[100];
- char line2[100];
- char line3[100];
- while (cin.getline(line1,100) )
- {
- cin.getline(line2, 100);
- cin.getline(line3, 100);
- cout << line3 << endl;
- cout << line1 << endl;
- cout << line2<< endl;
- }
- return 0;
- }
string to int
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main()
{
string s1,s2,s3,s1a="",s2a="",s3a="";
cin >> s1>>s2>>s3;
for (int i=0;i<s1.length();i++)
if (s1[i]>='0' && s1[i]<='9')
s1a = s1a + s1[i];
for (int i=0;i<s2.length();i++)
if (s2[i]>='0' && s2[i]<='9')
s2a = s2a + s2[i];
for (int i=0;i<s3.length();i++)
if (s3[i]>='0' && s3[i]<='9')
s3a = s3a + s3[i];
int n1,n2,n3;
istringstream(s1a) >>n1;
istringstream(s2a) >> n2;
istringstream(s3a) >>n3;
cout << n1+n2+n3<< endl;
return 0;
}
字元比對
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- string rstr, mstr;
- cin >> rstr >>mstr;
- int i=1,j=1;
- bool isOk = true;
- while (i<=rstr.length() && isOk == true)
- {
- while (rstr[i]!= mstr[j] && j<=mstr.length())
- {
- j++;
- }
- if (rstr[i]==mstr[j])
- {
- i++;
- j++;
- }
- else
- isOk = false;
- }
- if (isOk == true)
- cout << "YES" << endl;
- else
- cout << "NO" << endl;
- return 0;
- }
2014年6月5日 星期四
2014年6月4日 星期三
- // 小數點處理例
- #include <iostream>
- #include <cmath>
- #include <iomanip>
- using namespace std;
- int main()
- {
- int x1,y1,x2, y2;
- while (cin >> x1 >> y1 >> x2 >> y2)
- {
- double ans = sqrt((double)(x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
- cout.setf(ios::fixed, ios::floatfield);
- cout.precision(3);
- cout << ans << endl;
- }
- return 0;
- }