常见复杂度对应数据量表
例题2.1 abc
#includeusing namespace std;
int main()
{int a, b, c;
for(a=0;a<9;a++)
for(b=0;b<9;b++)
for (c = 0; c< 9; c++)
{ if ((a * 100 + b * 10 + c + b * 100 + c * 10 + c) == 532)
cout<< a<< " "<< b<< " "<< c<< endl;
}
return 0;
}
例题2.2 反序数
#includeusing namespace std;
int reverse(int number)
{int reversenumber = 0;
while (number != 0)
{reversenumber *= 10;
reversenumber += number % 10;
number /= 10;
}
return reversenumber;
}
int main()
{for (int i = 1000; i< 9999; i++)
if (i * 9 == reverse(i)) { cout<< i<< endl;
}
return 0;
}
例题2.3 对称平方数
#includeusing namespace std;
int Reverse(int number) {int reverseNumber = 0;
while (number != 0) {reverseNumber *= 10;
reverseNumber += number % 10;
number /= 10;
}
return reverseNumber;
}
int main() {for (int i = 1; i< 256; i++) {if (i * i == Reverse(i * i)) {cout<< i<< endl;
}
}
return 0;
}
2.图形排版例题2.4 输出梯形
#includeusing namespace std;
int main()
{int h; //梯形行数
while (cin >>h)
{int row = h;
int col = h + 2 * (h - 1); //推导公式得出列数
for (int i = 0; i< row; ++i)
{ for (int j = 0; j< col; ++j)
{ if (j< (col - (h + 2 * i))) //推导公式画出空格数
{cout<< " ";
}
else
{cout<< "*";
}
}
cout<< endl;
}
}
return 0;
}
3.日期问题例题2.5 今年的第几天
#includeusing namespace std;
int dayTable[2][13] = {{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
};
bool IsLeapYear(int year) {return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}
int main() {int Y, M, D;
while (cin >>Y >>M >>D) {int number = 0;
int row = IsLeapYear(Y);
for (int j = 0; j< M; j++) {number += dayTable[row][j];
}
number += D;
cout<< number<< endl;
}
return 0;
}
例题2.6 打印日期
#includeusing namespace std;
int dayTable[2][13] = {{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
};
bool IsLeapYear(int year) {return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}
int main() {int Y, M, D;
int number = 0;
while (cin >>Y >>number) {M = 0;
int row = IsLeapYear(Y);
while (number >dayTable[row][M]) {number -= dayTable[row][M];
M++;
}
D = number;
printf("%04d-%02d-%02d\n", Y, M, D);
}
return 0;
}
4.其他模拟例题2.7 手机键盘
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧
本文名称:数据结构考研学习笔记-创新互联
地址分享:https://www.cdcxhl.com/article38/dsjjsp.html
成都网站建设公司_创新互联,为您提供App开发、自适应网站、网站排名、网站建设、响应式网站、网站设计公司
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联