c_cpp 台科大工程狮养成计画程式
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 台科大工程狮养成计画程式相关的知识,希望对你有一定的参考价值。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
class PosSys(object):
__book_list = None
@classmethod
def __parse_csv_list(self):
if self.__book_list == None:
self.__book_list = []
csv_data = open("01-input.txt")
for line in csv_data.read().decode('utf-8').split('\n'):
if line == '':
continue
else:
self.__book_list.append(line.split(','))
@classmethod
def listAllBook(self):
self.__parse_csv_list()
for x in self.__book_list:
print x[1]
@classmethod
def searchBook(self):
self.__parse_csv_list()
keyword = raw_input('Enter a keyword: ')
result = filter(lambda x:x[1].encode('utf-8').find(keyword)!=-1, self.__book_list)
for x in result:
print x[1]
@classmethod
def sortByPrice(self, r):
self.__parse_csv_list()
for x in sorted(self.__book_list, reverse=r, key=lambda x:int(x[3])):
print x[1]
@classmethod
def sortByPrice0(self):
self.__parse_csv_list()
self.sortByPrice(False)
@classmethod
def sortByPrice1(self):
self.__parse_csv_list()
self.sortByPrice(True)
@classmethod
def computePrice(self):
self.__parse_csv_list()
books = raw_input('Enter book you buy (ex: 1,3,5): ')
sum = 0
for x in books.split(','):
print self.__book_list[int(x)+1][1], self.__book_list[int(x)+1][3]
sum += int(self.__book_list[int(x)+1][3])
print 'Total: ', sum
@classmethod
def error(slef):
print "Input Error"
if __name__ == '__main__':
while (True):
cmd = raw_input('> ')
{'0': PosSys.listAllBook,
'1': PosSys.searchBook,
'2': PosSys.sortByPrice0,
'3': PosSys.sortByPrice1,
'4': PosSys.computePrice
}.get(cmd, PosSys.error)()
print ''
#include <stdio.h>
#include <string.h>
int V[9]={0}, Ans[9];
char s[999];
void DFS(int start, int deep, int n){
if(deep == n){
for(int i = 0; i < deep; i++)
printf("%c", s[Ans[i]-1]);
puts("");
return ;
}
for(int i=n; i; --i){
if(V[i] == 0){
V[i] = 1;
Ans[deep] = i;
DFS(i, deep+1, n);
V[i] = 0;
}
}
}
int main() {
while(scanf("%s", s) != EOF) {
int len = strlen(s);
DFS(len, 0, len);
}
}
// 未實做 big number 大大手下留情
#include <stdio.h>
unsigned long long factorial(unsigned long long n) {
static unsigned long long cache[10000] = {0};
if (cache[n] != 0) return cache[n];
else
if (n==0 || n==1) return cache[n] = 1;
else return cache[n] = factorial(n-1) * n;
}
int main() {
unsigned long long n;
scanf("%llu", &n);
for (unsigned long long i=0; i<=n-1; ++i) {
for (unsigned long long j=0; j<=i; ++j)
printf("%llu ", factorial(i)/(factorial(j)*factorial(i-j)));
puts("");
}
}
#include <stdio.h>
int main() {
char c[11];
int s;
while(scanf("%s", c) != EOF) {
switch(c[0]) {
case 'A':
s = 1;
break;
case 'B':
s = 10;
break;
case 'C':
s = 19;
break;
case 'D':
s = 28;
break;
case '#':
s = 37;
break;
case 'F':
s = 46;
break;
case 'G':
s = 55;
break;
case 'H':
s = 64;
break;
case 'I':
s = 40;
break;
case 'J':
s = 73;
break;
case 'K':
s = 82;
break;
case 'L':
s = 2;
break;
case 'M':
s = 11;
break;
case 'N':
s = 20;
break;
case 'O':
s = 48;
break;
case 'P':
s = 29;
break;
case 'Q':
s = 38;
break;
case 'R':
s = 47;
break;
case 'S':
s = 56;
break;
case 'T':
s = 65;
break;
case 'U':
s = 74;
break;
case 'V':
s = 83;
break;
case 'W':
s = 21;
break;
case 'X':
s = 3;
break;
case 'Y':
s = 12;
break;
case 'Z':
s = 30;
}
for(int i=1;i<=8;++i) {
s += (9-i)*(c[i]-'0');
}
s += c[9]-'0';
printf("%s\n", s%10==0?"real":"fake");
}
}
# !/usr/bin/env ruby
n = gets().to_i
puts (1+n)*n/2
# !/usr/bin/env python
n = int(raw_input())
print (n and reduce(lambda x, y:x*y, xrange(1, n+1)) or 1)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>isPass</title>
</head>
<body>
<input id="score">
<div id="result"></div>
<script>
(function() {
function update() {
document.getElementById("result").innerHTML = (this.value<60 && "不及格") || "及格"
}
document.getElementById("score").addEventListener("change", update, false)
})()
</script>
</body>
</html>
class Todo(object):
def __init__(self):
self.__todo_list = []
def new(self):
content = raw_input('Enter todo: ')
self.__todo_list.append(content)
def ls(self):
if len(self.__todo_list) == 0:
print 'Todo list is empty'
else:
for i, x in enumerate(self.__todo_list):
print "%d: %s" %(i+1, x)
def rm(self):
index = int(raw_input('Enter todo index: '))
if len(self.__todo_list)+1 >= index:
self.__todo_list.pop(index-1)
else:
print 'index isn\'t in todo list'
def error(self):
print 'error'
todo = Todo()
print 'new: add new item'
print 'rm: remove a item'
print 'ls: list all item'
while True:
cmd = raw_input('> ')
{'new': todo.new,
'ls': todo.ls,
'rm': todo.rm
}.get(cmd, todo.error)()
print ''
# !/usr/bin/env python
# -*- coding: utf-8 -*-
x = int(raw_input())
print bin(x)[2:] + '(2)'
print hex(x)[2:] + '(16)'
#!/usr/bin/env python
# -*- coding: utf-8 -*-
f = open('08-input.txt')
m = -99999999
for x in f.readlines():
try:
tmp = int(x)
except:
continue
m = max(m, tmp)
print m
#include<iostream>
#include<sstream>
#include<cctype>
using namespace std;
int main()
{
string s;
while( getline( cin, s ) )
{
string oper;
stringstream ss;
char operators[1000] = {0};
int operands[1000] = {0};
int operators_length = 0;
int operands_length = 0;
ss.clear();
ss.str(s);
while( ss >> oper )
{
if( isdigit(oper[0]) )
{
int number = 0;
for( int i = 0 ; i < oper.length() ; i++ )
{
number *= 10;
number += oper[i]-'0';
}
operands[operands_length++] = number;
}
else
{
switch( oper[0] )
{
case '+': case '-':
while( operators_length > 0 )
{
if( operators[operators_length-1] == '+' )
{
operands[operands_length-2] += operands[operands_length-1];
operands_length--;
operators_length--;
}
else if( operators[operators_length-1] == '-' )
{
operands[operands_length-2] -= operands[operands_length-1];
operands_length--;
operators_length--;
}
else if( operators[operators_length-1] == '*' )
{
operands[operands_length-2] *= operands[operands_length-1];
operands_length--;
operators_length--;
}
else if( operators[operators_length-1] == '/' )
{
operands[operands_length-2] /= operands[operands_length-1];
operands_length--;
operators_length--;
}
else if( operators[operators_length-1] == '%' )
{
operands[operands_length-2] %= operands[operands_length-1];
operands_length--;
operators_length--;
}
else break;
}
operators[operators_length++] = oper[0];
break;
case '*': case '/': case '%':
while( operators_length > 0 )
{
if( operators[operators_length-1] == '*' )
{
operands[operands_length-2] *= operands[operands_length-1];
operands_length--;
operators_length--;
}
else if( operators[operators_length-1] == '/' )
{
operands[operands_length-2] /= operands[operands_length-1];
operands_length--;
operators_length--;
}
else if( operators[operators_length-1] == '%' )
{
operands[operands_length-2] %= operands[operands_length-1];
operands_length--;
operators_length--;
}
else break;
}
operators[operators_length++] = oper[0];
break;
case '(':
operators[operators_length++] = oper[0];
break;
case ')':
for( int i = operators_length-1; operators[i] != '(' ; i-- )
{
if( operators[i] == '+' )
{
operands[operands_length-2] += operands[operands_length-1];
operands_length--;
operators_length--;
}
if( operators[i] == '-' )
{
operands[operands_length-2] -= operands[operands_length-1];
operands_length--;
operators_length--;
}
if( operators[i] == '*' )
{
operands[operands_length-2] *= operands[operands_length-1];
operands_length--;
operators_length--;
}
if( operators[i] == '/' )
{
operands[operands_length-2] /= operands[operands_length-1];
operands_length--;
operators_length--;
}
if( operators[i] == '%' )
{
operands[operands_length-2] %= operands[operands_length-1];
operands_length--;
operators_length--;
}
}
operators_length--;
break;
}
}
}
for( operators_length-- ; operators_length >= 0 ; operators_length-- )
{
if( operators[operators_length] == '+' )
{
operands[operands_length-2] += operands[operands_length-1];
operands_length--;
}
if( operators[operators_length] == '-' )
{
operands[operands_length-2] -= operands[operands_length-1];
operands_length--;
}
if( operators[operators_length] == '*' )
{
operands[operands_length-2] *= operands[operands_length-1];
operands_length--;
}
if( operators[operators_length] == '/' )
{
operands[operands_length-2] /= operands[operands_length-1];
operands_length--;
}
if( operators[operators_length] == '%' )
{
operands[operands_length-2] %= operands[operands_length-1];
operands_length--;
}
}
cout << operands[0] << endl;
}
return 0;
}
以上是关于c_cpp 台科大工程狮养成计画程式的主要内容,如果未能解决你的问题,请参考以下文章
2017年"程序媛和工程狮"绝对不能忽视的编程语言框架和工具