“青軟杯”安徽科技學院第六屆程式設計大賽_非專業組
1299 Problem C | C互質個數 |
C互質個數
Time Limit:1000MS Memory Limit:65536K
Total Submit:21 Accepted:8
Description
貝貝、妞妞和康康都長大了,如今,他們已屆小學畢業,老師給貝貝出了一道強化計算的題目,讓她做一大堆除法,以確定兩個數之間是否有公共的因子,並且還要數清楚沒有公因子的數對。可是,畢竟有些數太大了,量又太多了,即使她與妞妞和康康聯手,也沒有耐心在一個小時做完這種吃力的事情啊。雖然他們真的知道該怎麼做,可是,他們的心早就飛到海邊的沙灘上了,想盡情地玩,但眼看又不能。能不能幫他們“減負”,儘早放飛心情,那就要靠你了。
Input
輸入若干組(≤100組)整數(每個整數n滿足0< n < 2^32),每組整數(個數≤50)佔一行(第一個數代表數字個數)。
Output
對每組整數,輸出其彼此互質的個數,每個結果單獨佔一行。
Sample Input
6 27 91 18 2 5 9
4 13 5 60 12
Sample Output
11
4
Source
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int jt(int a,int b) { return b==0?a:jt(b,a%b); } int main() { int n,a[100]= {0}; while(cin>>n) { int ans=0; memset(a,0,sizeof(a)); for(int i=0; i<n; i++) cin>>a[i]; for(int i=0; i<n; i++) for(int j=i+1; j<n; j++) if(jt(a[i],a[j])==1) ans++; cout<<ans<<endl; } return 0; }
1298 Problem D | B趣味求和 |
B趣味求和
Time Limit:1000MS Memory Limit:65536K
Total Submit:68 Accepted:14
Description
編寫一個程式,求Sn=a+aa+aaa+……+aa…aaa(有n個a)的值,其中a是一個數字。
Input
輸入資料含有不多於50組的資料,每組資料由兩個正整數(0<a, n < 10)組成。
Output
對於每組資料a和n,計算Sn=a+aa+aaa+……+aa…aaa(有n個a)的值,每個計算結果應單獨一行。
Sample Input
5 2
5 1
Sample Output
60
5
Source
#include<iostream>
using namespace std;
int main()
{
int a,n;
while(cin>>a>>n)
{
long long sb=0,sum=0;
for(int i=0;i<n;i++)
{
sb=sb*10+a;
sum+=sb;
}
cout<<sum<<endl;
}
return 0;
}
1300 Problem E | D重疊面積 |
D重疊面積
Time Limit:1000MS Memory Limit:65536K
Total Submit:50 Accepted:16
Description
zjahstu是個很厚道的ACMer,O(∩_∩)O~。。特為大家準備水題一道。。
題目很簡單,兩個矩形,告訴你矩形1,矩形2的面積和他們的總面積,請你求兩矩形重疊部分的面積。如果給你的情況不存在,就輸出Impossible。
Input
第一個數是T,表示測試資料的組數。 後面有T行,每行3個整數(1~10000)。
Output
輸出陰影部分的面積或者Impossible。
Sample Input
3
20 20 40
20 20 30
20 20 50
Sample Output
0
10
Impossible
Source
#include<iostream>
using namespace std;
int main()
{
int n;
cin>>n;
while(n--)
{
int a,b,c;
cin>>a>>b>>c;
if(a+b<c)cout<<"Impossible"<<endl;
else cout<<(a+b-c)<<endl;
}
return 0;
}
1301 Problem F | A+B' |
A+B'
Time Limit:1000MS Memory Limit:65536K
Total Submit:35 Accepted:14
Description
A+B'
Input
0 < =A,B < =1e6
Output
輸出答案
Sample Input
4 3
27 12
100 200
Sample Output
7
48
102
Hint
B'就是B反過來啦
Source
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
//Sample Input
//4 3
//27 12
//100 200
//Sample Output
//7
//48
//102
using namespace std;
long long f(long long n)
{
long long sum=0,a[10]= {0},i=0,m=n;
if(m<10)return m;
else
{
while(m)
{
a[i]=m%10;
i++;
m/=10;
}
for(int j=0; j<i; j++)
sum=sum*10+a[j];
return sum;
}
}
int main()
{
long long a,b;
while(cin>>a>>b)
{
long long sum=f(b);
cout<<a+sum<<endl;
}
return 0;
}
1302 Problem G | F數圈圈 |
F數圈圈
Time Limit:1000MS Memory Limit:65536K
Total Submit:39 Accepted:13
Description
幼兒園的小朋友對數字其實不是很感興趣,他們更感興趣的是形狀,現在給你一個數字,小朋友都會數出其中一共有多少圓圈圈
Input
一個數字n長度不超過19位
Output
輸出其中的圈圈數總數
Sample Input
14589
20869
12357
Sample Output
Hint
3 5 0
Source
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
using namespace std;
int main()
{
string s;
while(cin>>s)
{
int sum=0;
for(int i=0;i<s.length();i++)
{
if(s[i]=='0')sum++;
if(s[i]=='6')sum++;
if(s[i]=='8')sum+=2;
if(s[i]=='9')sum++;
}
cout<<sum<<endl;
}
return 0;
}
1303 Problem H | 誰比較2 |
誰比較2
Time Limit:1000MS Memory Limit:65536K
Total Submit:19 Accepted:12
Description
定義一個整數N中的2的指數為N二的級別,比如4=2^2則4的二度為2,6=2^1*a則6的二度為1
你的任務就是給出a,b中誰更2
Input
給出a,b 都是正數且不超過10000000
Output
給出a,b中誰更2
Sample Input
4 6
17 4
4 12
Sample Output
>
<
=
Source
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
using namespace std;
int jt(long long n)
{
int ans=0;
long long m=n;
if(m%2==1)return 0;
while(m%2==0)
{
ans++;
m/=2;
}
return ans;
}
int main()
{
long long a,b;
while(cin>>a>>b)
{
int x=jt(a),y=jt(b);
if(x>y)cout<<">"<<endl;
else if(x==y)cout<<"="<<endl;
else cout<<"<"<<endl;
}
return 0;
}
ok,非專業組的題目都是相當水的,只對學過c語言還掌握不熟的造成困擾,不到一個小時刷完。