Latest 100 public
snipts » a
showing 1-12 of 12 snipts for a
-
∞ Codeforces
#include <iostream> #include <cmath> using namespace std; long long f(long long k,long long t) { if(k%t==0) return k/t; else return (int)(fabs(k/t)+1); } int main() { long long n,m,a,y; cin>>n>>m>>a; y=f(n,a)*f(m,a); cout<<y;; return 0; }
-
∞ An exec <filename command redirects stdin to a file
19.1. Using exec An exec <filename command redirects stdin to a file. From that point on, all stdin comes from that file, rather than its normal source (usually keyboard input). This provides a method of reading a file line by line and possibly parsing each line of input using sed and/or awk. Example 19-1. Redirecting stdin using exec #!/bin/bash # Redirecting stdin using 'exec'. exec 6<&0 # Link file descriptor #6 with stdin. # Saves stdin. exec < data-file # stdin replaced by file "data-file" read a1 # Reads first line of file "data-file". read a2 # Reads second line of file "data-file." echo echo "Following lines read from file." echo "-------------------------------" echo $a1 echo $a2 echo; echo; echo exec 0<&6 6<&- # Now restore stdin from fd #6, where it had been saved, #+ and close fd #6 ( 6<&- ) to free it for other processes to use. # # <&6 6<&- also works. echo -n "Enter data " read b1 # Now "read" functions as expected, reading from normal stdin. echo "Input read from stdin." echo "----------------------" echo "b1 = $b1" echo exit 0 Similarly, an exec >filename command redirects stdout to a designated file. This sends all command output that would normally go to stdout to that file. Important exec N > filename affects the entire script or current shell. Redirection in the PID of the script or shell from that point on has changed. However . . . N > filename affects only the newly-forked process, not the entire script or shell. Thank you, Ahmed Darwish, for pointing this out. -
∞ image link con target _blank
<? $img_path = "images/arr_leggi_blu.gif"; $link_path = "node/47"; $theme_name = 'pmsth'; $options = array( 'attributes' => array( 'target' => '_blank', ), 'html' => true, ); $img = theme('image', drupal_get_path('theme', $theme_name). "/$img_path"); print l($img, $link_path, $options); ?>
-
∞ link con target _blank
<? $anchor = "anchor text"; $drupal_path = "node/47"; $options = array( 'attributes' => array( 'target' => '_blank', ) ); print l($anchor, $drupal_path, $options); ?>
-
∞ a
a -
∞ a
a -
∞ image link
<? $img_path = "images/arr_leggi_blu.gif"; $link_path = "node/47"; $theme_name = 'pmsth'; $img = theme('image', drupal_get_path('theme', $theme_name). "/$img_path"); print l($img, $link_path, array('html' => true)); ?>
-
∞ queue
#include <iostream> #include <queue> using namespace std; int main() { queue<int>myqueue; queue<int>myqueue2; for(int j=1;j<=10;j++) { myqueue.push(j); } int i; for(i=myqueue.size();i>0;i--) { cout<<myqueue.front()<<" "; myqueue2.push(myqueue.front()); myqueue.pop(); //removes the top element } cout<<endl<<endl; for(int h=1;h<=3;h++) { myqueue.push(myqueue2.front()); myqueue2.pop(); } for(i=myqueue2.size();i>0;i--) { cout<<myqueue2.front()<<" "; //myqueue2.push(myqueue.front()); myqueue2.pop(); //removes the top element } for(i=myqueue.size();i>0;i--) { cout<<myqueue.front()<<" "; //myqueue2.push(myqueue.front()); myqueue.pop(); //removes the top element } }
-
∞ Posting a link
<a href="http://URL" > the link < /a >
-
∞ A Recursive Example - Factorial
#include <iostream> using namespace std; int main() { int i=10; int recur_factorial(int i); cout<<recur_factorial( i); } int recur_factorial(int i) { if ( i == 0) return 1; else { return i * recur_factorial(i - 1); } } -
∞ s1
#include <iostream> #include <string> using namespace std; int main() { string s1; s1="Singapore Polytechnic is the oldest polytechnic!"; cout<<s1<<endl; s1.replace(29,6,"coolest"); cout<<s1; }
-
∞ template
#include <iostream > using namespace std; double l, h, w, Area, Volume; template <typename T> int calcArea( T h,T w) { Area = h*w; } template <typename N> int calcVol(N Area, N l) { Volume = l*Area; } int main() { cout<<"Please enter height: "; cin>>h; cout<<"Please enter width: "; cin>>w; cout<<"Please enter length: "; cin>>l; calcArea(h, w); calcVol(Area, l); cout<<"\nArea : "<<Area<<endl; cout<<"Volume : "<<Volume<<endl<<endl; cout<<":)"<<endl; cin.get(); cin.get(); return 0; }


