#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
int x=0,y=0;
//dir方向:1是右,2是左,3是上,4是下。
int dir=3;
//未移动标记。
int flag=0;
void setdir(char a)
{
if(a=='l')
{
switch(dir)
{
case 1:
dir=3;
break;
case 2:
dir=4;
break;
case 3:
dir=2;
break;
case 4:
dir=1;
break;
}
}
if(a=='r')
{
switch(dir)
{
case 1:
dir=4;
break;
case 2:
dir=3;
break;
case 3:
dir=1;
break;
case 4:
dir=2;
break;
}
}
return;
}
void go(int dis)
{
if(dir==1) x+=dis;
if(dir==2) x-=dis;
if(dir==3) y+=dis;
if(dir==4) y-=dis;
flag=1;
printf("(%d,%d)\n",x,y);
return;
}
int main()
{
int n;
scanf("%d",&n);
int i;
for(i=1;i<=n;i++)
{
char ins[20];
scanf("%s",ins);
if(isdigit(ins[0]))
go(atoi(ins));
if(ins[0]=='r')
setdir('r');
if(ins[0]=='l')
setdir('l');
}
if(flag==0) printf("(0,0)\n");
return 0;
}
RQNOJ 143 巨型整数
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
string s;
char in[20001];
scanf("%s",in);
s=in;
reverse(s.begin(),s.end());
string::iterator it=s.begin();
//此处需要注意,输入100须输出1。
while(*it=='0')
s.erase(it);
cout<<s<<endl;
long int sum=0;
for(it=s.begin();it!=s.end();it++)
sum+=(*it-'0');
cout<<sum;
return 0;
}
RQNOJ 133 统计数字
//第一次拙劣地使用了STL。以此纪念。
#include <stdio.h>
#include <set>
using namespace std;
int main()
{
set<int> num;
multiset<int> time;
int n,i,t;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&t);
num.insert(t);
time.insert(t);
}
set<int>::iterator it;
for(it=num.begin();it!=num.end();it++)
printf("%d %d\n",*it,time.count(*it));
return 0;
}
人人网Linux准客户端脚本
新春大礼,鄙人制作的人人网Linux准客户端脚本发布!
一些情况详见上一个版本《人人消息提醒》。
不同的是,这回可是全终端操作哦。需要wget和w3m。首次使用只需用w3m -cookie访问3g.renren.com取得cookie,以后全部使用w3m保存的cookie。
增加了快速访问。一旦有新消息,按下y便会启动w3m。
废话少说,上码!
搜索引擎shell:goosh.org
发现一个酷站:goosh.org。它是一个搜索引擎,准确地说,应该是一个搜索引擎的shell。它以google的服务为基础,我们可以像使用命令行一样使用它。
进入之后,会有这样一个提示符:
guest@goosh.org:/web>这时你只要输入关键词,然后回车即可。此时前4个搜索结果就会显示出来。直接输入序号并回车,即能在新窗口中打开你想要的url。如果对搜索结果不满意,直接回车便会再给出4个结果。
K&R C Bible Exercises 1-5
Modify the temperature conversion program to print the table in reverse order, that is, from 300 degrees to 0.
Example:
#include <stdio.h>
/* print Fahrenheit-Celsius table */
int main()
{
int fah;
printf("Fahrenheit-Celsius Table\n");
printf("%6s %6s\n","F","C");
printf("---------------\n");
for(fah=300;fah>=0;fah-=20)
printf("%6d %6.1f\n",fah,(fah-32)*5.0/9.0);
return 0;
}
K&R C Bible Exercises 1-4
Write a program to print the corresponding Celsius to Fahrenheit table.
Example:
#include <stdio.h>
/* print Celsius-Fahrenheit table */
int main()
{
float fah,cel,upper;
int step;
step=5;
cel=-20;
upper=50;
printf("Celsius-Fahrenheit Table\n");
printf("%6s %6s\n","C","F");
printf("---------------\n");
while(cel<=upper)
{
fah=cel*9.0/5.0+32;
printf("%6.0f %6.1f\n",cel,fah);
cel+=step;
}
return 0;
}
K&R C Bible Exercises 1-3
Modify the temperature conversion program to print a heading above the table.
Example:
#include <stdio.h>
/* print Fahrenheit-Celsius table */
int main()
{
float fah,cel,upper;
int step;
step=10;
fah=0;
upper=120;
printf("Fahrenheit-Celsius Table\n");
printf("%6s %6s\n","F","C");
printf("---------------\n");
while(fah<=upper)
{
cel=(fah-32)*5.0/9.0;
printf("%6.0f %6.1f\n",fah,cel);
fah+=step;
}
return 0;
}
K&R C Bible Exercises 1-2
Experiment to find out what happens when printf's argument string contains \c, where c is some character not listed above.
Example: I try to understand how \t works.
#include <stdio.h>
int main()
{
printf("Hello, World!\n\a");
printf("asdf56\tdfd\tsadfgg\nqe\tdfcvbnv\tdfafffffffsa\ndfdfaqerer\tdfa\tfdsab\n");
return 0;
}
K&R C Bible Exercises 1-1
Run the "hello, world" program on your system. Experiment with leaving out parts of the program, to see what error messages you get.
Example:
#include <stdio.h>
int main()
{
printf("Hello, World!\n");
return 0;
}