一些简单数据结构算法的实现1
来源:互联网 发布:ubuntu 开机脚本 编辑:程序博客网 时间:2024/05/20 20:58
http://pat.zju.edu.cn/contests/pat-practise/1005
#include<iostream>
#include<cstring>
#include<stack>
usingnamespace std;
int calculate(char num[]) {
int sum = 0;
for (int i = 0; i <strlen(num); i++)
sum += (num[i] - '0');
return sum;
}
char *digitToEnglish(int x)
{
switch(x)
{
case 0:return"zero";
case 1:return"one";
case 2:return"two";
case 3:return"three";
case 4:return"four";
case 5:return"five";
case 6:return"six";
case 7:return"seven";
case 8:return"eight";
case 9:return"nine";
}
}
void printEnglish(stack<int> s) {
int x;
while (!s.empty()) {
x = s.top();
s.pop();
cout <<" "<<digitToEnglish(x);
}
cout<<endl;
}
void print(int sum) {
stack<int> s;
while (sum>=10) {
s.push(sum % 10);
sum /= 10;
}
cout<<digitToEnglish(sum);
printEnglish(s);
}
int main() {
char num[101];
cin >> num;
int sum = calculate(num);
print(sum);
return 0;
}
http://pat.zju.edu.cn/contests/pat-practise/1008
#include<iostream>
using namespace std;
int main()
{
int n;
int target;
cin>>n;
int current=0;
int time=0;
while(n--)
{
cin>>target;
if(target>=current)
{
time+=(target-current)*6+5;
}
else
{
time+=(current-target)*4+5;
}
current=target;
}
cout<<time<<endl;
return 0;
}
http://pat.zju.edu.cn/contests/pat-practise/1036
#include<iostream>
#include<cstring>
usingnamespace std;
structstudent {
charname[11];
chargender[10];
charid[11];
intgrade;
};
int main() {
student femaleHigh;
student maleLow;
student temp;
femaleHigh.grade = -1;
maleLow.grade = 101;
int n;
cin >> n;
while (n--) {
cin>>temp.name>>temp.gender>>temp.id>>temp.grade;
if(strcmp(temp.gender,"M")==0&&temp.grade<=maleLow.grade)
{
strcpy(maleLow.name,temp.name);
strcpy(maleLow.gender,temp.gender);
strcpy(maleLow.id,temp.id);
maleLow.grade=temp.grade;
}elseif(strcmp(temp.gender,"F")==0&&temp.grade>=femaleHigh.grade)
{
strcpy(femaleHigh.name,temp.name);
strcpy(femaleHigh.gender,temp.gender);
strcpy(femaleHigh.id,temp.id);
femaleHigh.grade=temp.grade;
}
}
if(femaleHigh.grade!=-1)
{
cout<<femaleHigh.name<<" "<<femaleHigh.id<<endl;
}else{
cout<<"Absent"<<endl;
}
if(maleLow.grade!=101)
{
cout<<maleLow.name<<" "<<maleLow.id<<endl;
}else
{
cout<<"Absent"<<endl;
}
if(femaleHigh.grade!=-1&&maleLow.grade!=101)
{
cout<<femaleHigh.grade-maleLow.grade<<endl;
}else
{
cout<<"NA"<<endl;
}
return 0;
}
http://pat.zju.edu.cn/contests/pat-practise/1035
#include<iostream>
#include<cstring>
usingnamespace std;
structpeople {
charusername[11];
charpassword[11];
};
bool change(char *password) {
bool flag =false;
for (int i = 0; i <strlen(password); i++){
if (password[i] =='1') {
password[i] = '@';
flag = true;
}
if (password[i] =='0') {
password[i] = '%';
flag = true;
}
if (password[i] =='l') {
password[i] = 'L';
flag = true;
}
if (password[i] =='O') {
password[i] = 'o';
flag = true;
}
}
return flag;
}
int main() {
int n;
cin >> n;
int k = n;
char username[11];
char password[11];
people modify[1000];
int num = 0;
while (n--) {
cin >> username>> password;
if(change(password)) {
strcpy(modify[num].username, username);
strcpy(modify[num].password, password);
num++;
}
}
if (num == 0) {
if (k == 1) {
cout << "There is" << k<< " accountand no account is modified";
} else {
cout << "Thereare " << k<< "accounts and no account is modified";
}
} else {
cout << num<< endl;
for (int i = 0; i <num; i++)
cout <<modify[i].username <<" " <<modify[i].password << endl;
}
return 0;
}
- 一些简单数据结构算法的实现1
- 一些简单数据结构算法的实现2
- 一些简单数据结构算法的实现3
- 一些简单数据结构算法的实现4
- 一些简单数据结构算法的实现4
- 【数据结构与算法】String 的简单实现
- 一些简单算法实现
- 数据结构的一些算法
- 一些数据结构的实现
- 数据结构Java版的排序算法的简单实现
- 一些简单的算法
- 一些简单的算法
- 【数据结构与算法】【排序】简单选择排序的代码实现
- 算法与数据结构基础3:C++单链表类的简单实现
- 算法与数据结构基础5:C++栈的简单实现
- 算法与数据结构基础6:C++队列的简单实现
- 算法与数据结构基础7:C++双链表的简单实现
- 【数据结构与算法】(三) c 语言栈的简单实现
- setInterval 传值 设参数
- 在Linux中使用蓝牙
- 蓝芽:Linux与手机
- 1012 u Calculate e
- Linux基本命令:如何卸载Linux程序
- 一些简单数据结构算法的实现1
- centos6.0下如何卸载linux版google chrome [复制链接]
- DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Su
- android编译之解析main.mk
- Transport t=session.getTransport();
- 一些简单数据结构算法的实现2
- Linux rpm 命令参数使用详解[介绍和应用]
- Chrome(Google浏览器)中使用debug版的flash player
- php Class ‘mysqli’ not found 问题