#include <stdio.h>
#include <time.h>
#include <stdlib.h>
const int YI_YAO_SAN_BIAN=3; //一爻三变
const int YI_GUA_LIU_YAO=6; //一卦六爻
const int Liu_Shi_Si_Gua=64; //六十四卦
const int DA_YAN_ZHI_SHU=50; //大衍之数为50
const int LAO_YANG=9; //老阳
const int LAO_YIN=6; //老阴
int main()
{
int left,right,stick;
int result[DA_YAN_ZHI_SHU];
int C,P=1,i,j,k,m,n,flag;
srand( time(NULL) );
for(i=1;i<=Liu_Shi_Si_Gua;i++)
{
C=0;
for(j=1;j<=YI_GUA_LIU_YAO;j++)
{
stick=DA_YAN_ZHI_SHU-1;
for(k=1;k<=YI_YAO_SAN_BIAN;k++)
{
stick--; //挂一
//分两
left=(rand()%(stick-2))+2;
right=stick-left;
//揲四
left%=4;
if(left==0)
left=4;
right%=4;
if(right==0)
right=4;
stick-=(left+right); //归奇
}//for(YI_YAO_SAN_BIAN)
result[C++]=stick/4; //保存一爻的结果
}//for(YI_GUA_LIU_YAO)
//输出一卦的结果
printf("第 %2d 卦:\n",P++);
for(n=0;n<YI_GUA_LIU_YAO;n++)
printf("%d ",result[n]);
printf("\n");
for(n=0,flag=0;n<YI_GUA_LIU_YAO;n++) //flag 指示六爻中是否出现了老阴或者老阳
{
printf("%d ",result[n]%2);
if(result[n]==LAO_YANG||result[n]==LAO_YIN)
flag=1;
}
if(flag) //六爻中出现了老阴或者老阳
{
for(n=0;n<YI_GUA_LIU_YAO;n++)
printf("% d",(result[n]+1)%2); // 阴阳变换
}
printf("\n");
}//for(Liu_Shi_Si_Gua)
}
12345678910111213141516171819202122232425262728#include <stdio.h>#include <math.h>float f(float x, float y, float z) { float a = x * x + 9.0f / 4.0f * y * y + z * z - 1; return a * a * a - x * x * z * z * z - 9.0f / 80.0f * y * y * z * z * z;}float h(float x, float z) { for (float y = 1.0f; y >= 0.0f; y -= 0.001f) if (f(x, y, z) <= 0.0f) return y; return 0.0f;}int main() { for (float z = 1.5f; z > -1.5f; z -= 0.05f) { for (float x = -1.5f; x < 1.5f; x += 0.025f) { float v = f(x, 0.0f, z); if (v <= 0.0f) { float y0 = h(x, z); float ny = 0.01f; float nx = h(x + ny, z) - y0; float nz = h(x, z + ny) - y0; float nd = 1.0f / sqrtf(nx * nx + ny * ny + nz * nz); float d = (nx + ny - nz) * nd * 0.5f + 0.5f; putchar(".:-=+*#%@"[(int)(d * 5.0f)]); } else putchar(' '); } putchar('\n'); }}
如何用c语言画出生日快乐?
用qt做一个界面,界面里面只有一张动态图,有一个菜单可以打开文件选择动态图,用qt就可以做出来,关于音乐,用system函数或者linux下的函数,调用程序就可以把音乐也播放出来。
应该是要用两个线程显示动态图不知道是直接显示还是要一直刷新,所以可能是两个线程。
#include
#include
float f(float x, float y, float z) {
float a = x * x + 9.0f / 4.0f * y * y + z * z - 1;
return a * a * a - x * x * z * z * z - 9.0f / 80.0f * y * y * z * z * z;}float h(float x, float z) {
for (float y = 1.0f; y >= 0.0f; y -= 0.001f)
if (f(x, y, z) return y;
return 0.0f;}
int main() {
for (float z = 1.5f; z >-1.5f; z -= 0.05f) {
for (float x = -1.5f; x float v = f(x, 0.0f, z);
if (v float y0 = h(x, z);
float ny = 0.01f;
float nx = h(x + ny, z) - y0;
float nz = h(x, z + ny) - y0;
float nd = 1.0f / sqrtf(nx * nx + ny * ny + nz * nz);
float d = (nx + ny - nz) * nd * 0.5f + 0.5f;
putchar(".:-=+*#%@"[(int)(d * 5.0f)]);
}
else
putchar(' ');
}
putchar('\n');
}
}
楼主要求用C,麻烦呢,如果用C++倒是方便多了,闲着没事做,简单写了下,看下就好#include #include #include #include using namespace std;struct BirthInfo{ int month; int day; BirthInfo() { month = 0; day = 0; } bool operator == (const BirthInfo& rhs ) const { if ( month == rhs.month && day == rhs.day ) { return true; } return false; } bool operator StrNoList; SameBirthInfo() { nCount = 0; }};typedef map Result;int main(){ int nStudentCount = 0; string strNo = ""; BirthInfo BirInfo; Result result; SameBirthInfo sameBirthInfo; cin >> nStudentCount; while( nStudentCount -- > 0 ) { cin >> strNo >> BirInfo.month >> BirInfo.day; Result::iterator iter = result.find( BirInfo ); if ( iter == result.end() ) { //找不到 pair pInsRet = result.insert( Result::value_type(BirInfo,sameBirthInfo) ); if ( pInsRet.second ) { pInsRet.first->second.nCount = 1; //记录下此生日有一人 pInsRet.first->second.StrNoList.push_back( strNo ); //记录下此人学号 } } else { //找到 iter->second.nCount++; //同一天生日人数++ iter->second.StrNoList.push_back( strNo ); //保存下这个学生的学号 } } //输出所有结果 Result::const_iterator cIter = result.begin(); while ( cIter != result.end() ) { //先输出生日 cout first.month first.day; //输出所有学生学号 list::const_iterator cStrIter = cIter->second.StrNoList.begin(); while ( cStrIter != cIter->second.StrNoList.end() ) { cout c_str(); ++cStrIter; } cout 追问: Σ( ° △ °。
)︴ 太。太厉害,只是窝一弱渣,看不懂C++。能麻烦说说使用什么结构么?是顺序查找字典么? 追答: 用的其实就是map字典,我把学生的生日(月和日)作为一个查找键,找不到,就插入新的,找到了,就更新该键对应下面的学生信息至于为什么要弄一个nCount来保存个数,方便你说的要求选中三个以上什么的而已,呵呵~ 评论0 0 0。
#include