Ural 1044 Lucky tickets. Easy!

注意的是这里的n位数可以以0打头

#include<iostream>
using namespace std;

void f2()
{
     
int count=0;
     
for(int i1=0; i1<=9; i1++)
     
for(int i2=0; i2<=9; i2++)
             
if(i1==i2)count++;
     cout
<<count<<endl;
}

void f4()
{
     
int count=0;
     
for(int i1=0; i1<=9; i1++)
     
for(int i2=0; i2<=9; i2++)
     
for(int i3=0; i3<=9; i3++)
     
for(int i4=0; i4<=9; i4++)
             
if(i1+i2==i3+i4)count++;
     cout
<<count<<endl;
}

void f6()
{
     
int count=0;
     
for(int i1=0; i1<=9; i1++)
     
for(int i2=0; i2<=9; i2++)
     
for(int i3=0; i3<=9; i3++)
     
for(int i4=0; i4<=9; i4++)
     
for(int i5=0; i5<=9; i5++)
     
for(int i6=0; i6<=9; i6++)
             
if(i1+i2+i3==i5+i4+i6)count++;
     cout
<<count<<endl;
}

void f8()
{
     
int count=0;
     
for(int i1=0; i1<=9; i1++)
     
for(int i2=0; i2<=9; i2++)
     
for(int i3=0; i3<=9; i3++)
     
for(int i4=0; i4<=9; i4++)
     
for(int i5=0; i5<=9; i5++)
     
for(int i6=0; i6<=9; i6++)
     
for(int i7=0; i7<=9; i7++)
     
for(int i8=0; i8<=9; i8++)
             
if(i1+i2+i3+i4==i5+i7+i6+i8)count++;
     cout
<<count<<endl;
}

int main()
{
    
int n;
    cin
>>n;
    
if(n==2)f2();
    
else if(n==4)f4();
    
else if(n==6)f6();
    
else if(n==8)f8();
    
    system(
"pause");
    
return 0;
}

posted on 2010-06-23 23:36 田兵 阅读(235) 评论(0)  编辑 收藏 引用 所属分类: URAL


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2010年6月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

导航

统计

常用链接

留言簿(2)

随笔分类(65)

随笔档案(65)

文章档案(2)

ACM

搜索

积分与排名

最新随笔

最新评论

阅读排行榜